@graphcommerce/googletagmanager 11.0.0-canary.46 → 11.0.0-canary.48

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
@@ -1,5 +1,13 @@
1
1
  # Change Log
2
2
 
3
+ ## 11.0.0-canary.48
4
+
5
+ ### Patch Changes
6
+
7
+ - [#2690](https://github.com/graphcommerce-org/graphcommerce/pull/2690) [`ad99107`](https://github.com/graphcommerce-org/graphcommerce/commit/ad9910732b4f0b251a7586f8d35e621c6cf0d607) - The `sendEvent` plugin reads `googleEventNames` when it sends an event. It loads before `google-datalayer` defines `googleEventNames`, so it threw a `TypeError` in development. ([@bramvanderholst](https://github.com/bramvanderholst))
8
+
9
+ ## 11.0.0-canary.47
10
+
3
11
  ## 11.0.0-canary.46
4
12
 
5
13
  ## 11.0.0-canary.45
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@graphcommerce/googletagmanager",
3
3
  "homepage": "https://www.graphcommerce.org/",
4
4
  "repository": "github:graphcommerce-org/graphcommerce",
5
- "version": "11.0.0-canary.46",
5
+ "version": "11.0.0-canary.48",
6
6
  "sideEffects": false,
7
7
  "prettier": "@graphcommerce/prettier-config-pwa",
8
8
  "eslintConfig": {
@@ -15,11 +15,11 @@
15
15
  "@types/gapi.client.tagmanager": "^2.0.4"
16
16
  },
17
17
  "peerDependencies": {
18
- "@graphcommerce/eslint-config-pwa": "^11.0.0-canary.46",
19
- "@graphcommerce/google-datalayer": "11.0.0-canary.46",
20
- "@graphcommerce/next-ui": "^11.0.0-canary.46",
21
- "@graphcommerce/prettier-config-pwa": "^11.0.0-canary.46",
22
- "@graphcommerce/typescript-config-pwa": "^11.0.0-canary.46",
18
+ "@graphcommerce/eslint-config-pwa": "^11.0.0-canary.48",
19
+ "@graphcommerce/google-datalayer": "11.0.0-canary.48",
20
+ "@graphcommerce/next-ui": "^11.0.0-canary.48",
21
+ "@graphcommerce/prettier-config-pwa": "^11.0.0-canary.48",
22
+ "@graphcommerce/typescript-config-pwa": "^11.0.0-canary.48",
23
23
  "@mui/material": "^7.0.0",
24
24
  "next": "*",
25
25
  "react": "^19.2.0",
@@ -0,0 +1,29 @@
1
+ // @vitest-environment happy-dom
2
+
3
+ import { afterEach, expect, it, vi } from 'vitest'
4
+
5
+ const datalayer = vi.hoisted(() => ({ googleEventNames: undefined as string[] | undefined }))
6
+
7
+ // google-datalayer loads this plugin through the sendEvent interceptor before it defines googleEventNames.
8
+ vi.mock('@graphcommerce/google-datalayer', () => ({
9
+ get googleEventNames() {
10
+ return datalayer.googleEventNames
11
+ },
12
+ }))
13
+
14
+ afterEach(() => {
15
+ window.dataLayer = undefined
16
+ })
17
+
18
+ it('reads the event names of google-datalayer when it sends an event', async () => {
19
+ const { sendEvent } = await import('./tagmanagerEvent')
20
+ datalayer.googleEventNames = ['view_item']
21
+ window.dataLayer = []
22
+
23
+ sendEvent(() => {}, 'view_item', { items: [] })
24
+
25
+ expect(window.dataLayer).toEqual([
26
+ { ecommerce: null },
27
+ { event: 'view_item', ecommerce: { items: [] } },
28
+ ])
29
+ })
@@ -13,12 +13,10 @@ declare global {
13
13
  }
14
14
  }
15
15
 
16
- const ecommerceEvents = new RegExp(`${googleEventNames.join('|')}`, 'i')
17
-
18
16
  export const sendEvent: FunctionPlugin<typeof sendEventType> = (prev, eventName, eventData) => {
19
17
  prev(eventName, eventData)
20
18
 
21
- if (ecommerceEvents.test(eventName)) {
19
+ if (new RegExp(`${googleEventNames.join('|')}`, 'i').test(eventName)) {
22
20
  window.dataLayer?.push({ ecommerce: null })
23
21
  // console.log(eventName, eventData)
24
22
  window.dataLayer?.push({ event: eventName, ecommerce: eventData })