New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@ag.common/analytics

Package Overview
Dependencies
Maintainers
0
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ag.common/analytics

The `@ag.common/analytics` package aims to coordinate analytics capture across the export service. We ship the correct tracking codes out of the box for Hotjar and Google Analytics so that everything is reported to the right place.

  • 0.8.0
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
4
decreased by-63.64%
Maintainers
0
Weekly downloads
 
Created
Source

Analytics

The @ag.common/analytics package aims to coordinate analytics capture across the export service. We ship the correct tracking codes out of the box for Hotjar and Google Analytics so that everything is reported to the right place.

It also provides convenient helpers for reporting custom events and managing data contexts.

See the storybook for more examples.

Installation

yarn add @ag.common/analytics

Basic usage

import Script from 'next/script';
import { Analytics } from '@ag.common/analytics';

function App() {
	return (
		<Analytics scriptComponents={{ Script }}>
			<YourApplication />
		</Analytics>
	);
}

Disable an analytics script

Hotjar and Google Analytics are enabled by default but can be turned off one by one.

import Script from 'next/script';
import { Analytics } from '@ag.common/analytics';

function App() {
	return (
		<Analytics
			scriptComponents={{ Script }}
			hotjar={false}
			googleAnalytics={false}
		>
			<YourApplication />
		</Analytics>
	);
}

Trigger analytics events

Events are reported to Google Analytics by default

import Script from 'next/script';
import { Analytics, useAnalytics } from '@ag.common/analytics';

function TrackingButton() {
	const { trackEvent } = useAnalytics();

	return (
		<Button
			onClick={() => {
				trackEvent('login');
			}}
		>
			Log in
		</Button>
	);
}

function App() {
	return (
		<Analytics scriptComponents={{ Script }}>
			<p>Log in to get started</p>

			<TrackingButton />
		</Analytics>
	);
}

Custom event handlers

You can report to an alternative analytics provider by providing an onEvent callback

import Script from 'next/script';
import { Analytics } from '@ag.common/analytics';

function App() {
	return (
		<Analytics
			scriptComponents={{ Script }}
			onEvent={(name, data) => logger.info(name, data)}
		>
			<YourApplication />
		</Analytics>
	);
}

FAQs

Package last updated on 11 Dec 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc