From d349517f5e8be6725213733d33dfe0b0a7888b01 Mon Sep 17 00:00:00 2001 From: Paulo Date: Thu, 14 Oct 2021 10:14:28 +0100 Subject: [PATCH] Fix trackingHeadScript not triggering events (#18) * Fix trackingHeadScript not triggering events * Fix tests not running --- README.md | 2 +- package-lock.json | 4 ++-- package.json | 2 +- src/components/TrackingHeadScript.tsx | 21 ++++++++++++--------- 4 files changed, 16 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 78e507f..4d8da93 100755 --- a/README.md +++ b/README.md @@ -84,7 +84,7 @@ trackEvent({ | Parameter | Type | Default | Notes | | ---------- | --------- | --------- | ------------------------------------------------------------------- | -| **id** | `string` | undefined | Same ID used in `trackingHeadScript`. Example format: `GTM-xxxxxx`. | +| **id** | `string` | undefined | Same ID used in `TrackingHeadScript`. Example format: `GTM-xxxxxx`. | | **enable** | `boolean` | true | Used to enable or disable tracking events. | **Note**: This _should_ only be used if needed, for example after user has consented to being tracked. You _shouldn't_ need to toggle this in normal usage. diff --git a/package-lock.json b/package-lock.json index bdc3728..225e1a4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@phntms/react-gtm", - "version": "0.1.0", + "version": "0.1.1", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "@phntms/react-gtm", - "version": "0.1.0", + "version": "0.1.1", "license": "MIT", "devDependencies": { "@babel/preset-env": "^7.4.5", diff --git a/package.json b/package.json index 3b24af2..335e7b3 100755 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@phntms/react-gtm", "description": "A lightweight React library to implement custom Google Tag Manager events.", - "version": "0.1.0", + "version": "0.1.1", "main": "lib/index.js", "types": "lib/index.d.ts", "homepage": "https://github.com/phantomstudios/react-gtm#readme", diff --git a/src/components/TrackingHeadScript.tsx b/src/components/TrackingHeadScript.tsx index d8df807..cf63881 100644 --- a/src/components/TrackingHeadScript.tsx +++ b/src/components/TrackingHeadScript.tsx @@ -10,16 +10,19 @@ const TrackingHeadScript = ({ id, disable = false }: EmbedTrackingProps) => ( async src={`https://www.googletagmanager.com/gtag/js?id=${id}`} /> - + function gtag() { dataLayer.push(arguments); } + gtag('js', new Date()); + gtag('config', '${id}', { page_path: window.location.pathname }); + `, + }} + /> )}