@graphcommerce/googletagmanager 0.2.10 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,28 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [1.0.1](https://github.com/ho-nl/m2-pwa/compare/@graphcommerce/googletagmanager@0.3.2...@graphcommerce/googletagmanager@1.0.1) (2021-11-03)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * simplified google tagmanager and create 1.0.0 ([21ac284](https://github.com/ho-nl/m2-pwa/commit/21ac28484de6c12d54f6cf73ad04e459d74892a7))
12
+
13
+
14
+
15
+
16
+
17
+ # [0.3.0](https://github.com/ho-nl/m2-pwa/compare/@graphcommerce/googletagmanager@0.2.10...@graphcommerce/googletagmanager@0.3.0) (2021-10-27)
18
+
19
+
20
+ ### Features
21
+
22
+ * **nextjs:** upgraded to nextjs 12 ([9331bc8](https://github.com/ho-nl/m2-pwa/commit/9331bc801f6419522115cc47d291d49d608d5a90))
23
+
24
+
25
+
26
+
27
+
6
28
  ## [0.2.1](https://github.com/ho-nl/m2-pwa/compare/@graphcommerce/googletagmanager@0.2.0...@graphcommerce/googletagmanager@0.2.1) (2021-09-27)
7
29
 
8
30
  **Note:** Version bump only for package @graphcommerce/googletagmanager
package/README.md CHANGED
@@ -6,14 +6,9 @@ webshop.
6
6
  ### Usage
7
7
 
8
8
  1. Fill `NEXT_PUBLIC_GTM_ID` in your .env file
9
-
10
- 2. add `<GoogleTagManagerScript/>` to your \_app.tsx file, preferably as high as
11
- you can in the component hierarchy
12
-
13
- 3. add `<GoogleTagManagerNoScript/>` to your \_document.tsx file, in the body
14
- section above `<Main />`
15
-
16
- ### Hooks
17
-
18
- `useGTMPageViewEvent` - every time a route history change happens, pageview
19
- event gets triggered
9
+ [example](../../examples/magento-graphcms/.env.example)
10
+ 2. Add `<GoogleTagManagerScript/>` to your `pages/_app.tsx` file.
11
+ [example](../../examples/magento-graphcms/pages/_app.tsx)
12
+ 3. Add `<GoogleTagManagerNoScript/>` to your `pages/_document.tsx` file, in the
13
+ body section above `<Main />`
14
+ [example](../../examples/magento-graphcms/pages/_document_.tsx)
@@ -1,10 +1,27 @@
1
+ import { useRouter } from 'next/router'
1
2
  import Script from 'next/script'
2
- import React from 'react'
3
+ import React, { useEffect } from 'react'
3
4
 
4
5
  export default function GoogleTagManagerScript() {
5
6
  const id = process.env.NEXT_PUBLIC_GTM_ID
6
7
 
7
- if (!id) console.warn('[@graphcommerce/googletagmanager]', 'NEXT_PUBLIC_GTM_ID not found')
8
+ if (process.env.NODE_ENV !== 'production' && !id)
9
+ console.warn('[@graphcommerce/googletagmanager]: NEXT_PUBLIC_GTM_ID not found')
10
+
11
+ const router = useRouter()
12
+
13
+ useEffect(() => {
14
+ const onRouteChangeComplete = (url: string) => {
15
+ const dataLayer = globalThis.dataLayer as Record<string, unknown>[]
16
+ dataLayer.push({ event: 'pageview', page: url })
17
+ }
18
+
19
+ router.events.on('routeChangeComplete', onRouteChangeComplete)
20
+
21
+ return () => {
22
+ router.events.off('routeChangeComplete', onRouteChangeComplete)
23
+ }
24
+ }, [router.events])
8
25
 
9
26
  return (
10
27
  <Script
package/index.ts CHANGED
@@ -1,2 +1 @@
1
1
  export * from './components'
2
- export * from './hooks'
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@graphcommerce/googletagmanager",
3
- "version": "0.2.10",
3
+ "version": "1.0.1",
4
4
  "sideEffects": false,
5
5
  "prettier": "@graphcommerce/prettier-config-pwa",
6
6
  "browserslist": [
@@ -14,19 +14,16 @@
14
14
  },
15
15
  "devDependencies": {
16
16
  "@graphcommerce/browserslist-config-pwa": "^3.0.2",
17
- "@graphcommerce/eslint-config-pwa": "^3.1.1",
17
+ "@graphcommerce/eslint-config-pwa": "^3.1.3",
18
18
  "@graphcommerce/prettier-config-pwa": "^3.0.3",
19
19
  "@graphcommerce/typescript-config-pwa": "^3.1.1",
20
- "@playwright/test": "^1.15.2"
20
+ "@playwright/test": "^1.16.2",
21
+ "@types/gapi.client.tagmanager": "^2.0.2"
21
22
  },
22
23
  "dependencies": {
23
- "@apollo/client": "^3.4.16",
24
- "@graphcommerce/graphql": "^2.104.1",
25
- "@graphql-typed-document-node/core": "^3.1.0",
26
- "clsx": "^1.1.1",
27
- "next": "^11.1.2",
24
+ "next": "^12.0.2",
28
25
  "react": "^17.0.2",
29
26
  "react-dom": "^17.0.2"
30
27
  },
31
- "gitHead": "a71eb508e3ddf42e5705e23bc8016f6f08969c74"
28
+ "gitHead": "7aca802dd74632aa2f474eae2d93bd563490fd90"
32
29
  }
package/hooks/index.ts DELETED
@@ -1 +0,0 @@
1
- export { default as useGTMPageViewEvent } from './useGTMPageViewEvent'
@@ -1,29 +0,0 @@
1
- import { useRouter } from 'next/router'
2
- import { useEffect } from 'react'
3
-
4
- type useGTMPageViewEventProps = {
5
- variables?: { [key: string]: string | number }
6
- }
7
-
8
- export default function useGTMPageViewEvent(props: useGTMPageViewEventProps = {}) {
9
- const { variables } = props
10
- const router = useRouter()
11
-
12
- useEffect(() => {
13
- const onRouteChangeComplete = (url: string) => {
14
- const win = window as any
15
-
16
- win.dataLayer.push({
17
- event: 'pageview',
18
- page: url,
19
- ...variables,
20
- })
21
- }
22
-
23
- router.events.on('routeChangeComplete', onRouteChangeComplete)
24
-
25
- return () => {
26
- router.events.off('routeChangeComplete', onRouteChangeComplete)
27
- }
28
- }, [router.events, variables])
29
- }