Socket
Socket
Sign inDemoInstall

@haensl/google-analytics

Package Overview
Dependencies
2
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 1.0.1 to 1.1.0

33

index.js
import { platform } from '@haensl/services';
if (platform.hasWindow) {
if (!window.dataLayer) {
window.dataLayer = [];
}
if (!window.gtag) {
window.gtag = function(...args) {
window.dataLayer.push(args);
};
}
window.gtag('js', new Date());
}
// European Union

@@ -47,2 +33,18 @@ export const regionEU = [

export const install = () => {
if (platform.hasWindow) {
if (!window.dataLayer) {
window.dataLayer = [];
}
if (!window.gtag) {
window.gtag = function(...args) {
window.dataLayer.push(args);
};
}
window.gtag('js', new Date());
}
};
export const init = ({

@@ -60,2 +62,4 @@ measurementId,

install();
window.gtag('config', measurementId, {

@@ -162,2 +166,3 @@ anonymize_ip: anonymizeIp,

init,
install,
consent,

@@ -164,0 +169,0 @@ event,

{
"name": "@haensl/google-analytics",
"version": "1.0.1",
"version": "1.1.0",
"description": "Google Analytics 4 service abstraction for gtag and measurement protocol.",

@@ -5,0 +5,0 @@ "module": "index.js",

@@ -50,2 +50,3 @@ # @haensl/google-analytics

* [`init(confg)`](#tag/init): Initialize the gtag module.
* [`install`](#tag/install): Installs gtag stubs on `window`.
* [`consent(granted)`](#tag/consent): Consent to tracking.

@@ -77,3 +78,3 @@ * [`event(data)`](#tag/event): Track an event.

Initializes the tracking module. You only need to call this once, e.g. when your app boots.
Initializes the tracking module. You only need to call this once, e.g. when your app boots. This also calls [`install()`](#tag/install).

@@ -114,2 +115,8 @@ Tracking consent is defaulted to `false` for EU region. See [`consent()`](#tag/consent).

#### `install()` <a name="tag/install"></a>
`import { install } from '@haensl/google-analytics'`
Installs `window.dataLayer` and `window.gtag` stubs, i.e. [Google Docs](https://developers.google.com/tag-platform/tag-manager/datalayer#installation). Is called on [`init()`](#tag/init).
#### `consent(granted = false)` <a name="tag/consent"></a>

@@ -116,0 +123,0 @@

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc