@graphcommerce/google-datalayer 8.1.0-canary.5 → 8.1.0-canary.52

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,104 @@
1
1
  # @graphcommerce/google-datalayer
2
2
 
3
+ ## 8.1.0-canary.52
4
+
5
+ ## 8.1.0-canary.51
6
+
7
+ ## 8.1.0-canary.50
8
+
9
+ ## 8.1.0-canary.49
10
+
11
+ ## 8.1.0-canary.48
12
+
13
+ ## 8.1.0-canary.47
14
+
15
+ ## 8.1.0-canary.46
16
+
17
+ ## 8.1.0-canary.45
18
+
19
+ ## 8.1.0-canary.44
20
+
21
+ ## 8.1.0-canary.43
22
+
23
+ ## 8.1.0-canary.42
24
+
25
+ ## 8.1.0-canary.41
26
+
27
+ ## 8.1.0-canary.40
28
+
29
+ ## 8.1.0-canary.39
30
+
31
+ ## 8.1.0-canary.38
32
+
33
+ ## 8.1.0-canary.37
34
+
35
+ ## 8.1.0-canary.36
36
+
37
+ ## 8.1.0-canary.35
38
+
39
+ ## 8.1.0-canary.34
40
+
41
+ ## 8.1.0-canary.33
42
+
43
+ ## 8.1.0-canary.32
44
+
45
+ ## 8.1.0-canary.31
46
+
47
+ ## 8.1.0-canary.30
48
+
49
+ ## 8.1.0-canary.29
50
+
51
+ ## 8.1.0-canary.28
52
+
53
+ ## 8.1.0-canary.27
54
+
55
+ ## 8.1.0-canary.26
56
+
57
+ ## 8.1.0-canary.25
58
+
59
+ ## 8.1.0-canary.24
60
+
61
+ ## 8.1.0-canary.23
62
+
63
+ ## 8.1.0-canary.22
64
+
65
+ ## 8.1.0-canary.21
66
+
67
+ ## 8.1.0-canary.20
68
+
69
+ ### Patch Changes
70
+
71
+ - [#2246](https://github.com/graphcommerce-org/graphcommerce/pull/2246) [`fc5c04d`](https://github.com/graphcommerce-org/graphcommerce/commit/fc5c04d4a2c0301be7d3cc983d9b31f6fcaf6fe6) - Create useRemoveItemFromCart hook to allow for reuse while keeping compatibility with plugins.
72
+ ([@Jessevdpoel](https://github.com/Jessevdpoel))
73
+
74
+ ## 8.1.0-canary.19
75
+
76
+ ## 8.1.0-canary.18
77
+
78
+ ## 8.1.0-canary.17
79
+
80
+ ## 8.1.0-canary.16
81
+
82
+ ## 8.1.0-canary.15
83
+
84
+ ## 8.1.0-canary.14
85
+
86
+ ## 8.1.0-canary.13
87
+
88
+ ## 8.1.0-canary.12
89
+
90
+ ## 8.1.0-canary.11
91
+
92
+ ## 8.1.0-canary.10
93
+
94
+ ## 8.1.0-canary.9
95
+
96
+ ## 8.1.0-canary.8
97
+
98
+ ## 8.1.0-canary.7
99
+
100
+ ## 8.1.0-canary.6
101
+
3
102
  ## 8.1.0-canary.5
4
103
 
5
104
  ## 8.0.6-canary.4
package/Config.graphqls CHANGED
@@ -1,4 +1,7 @@
1
1
  extend input GraphCommerceConfig {
2
+ """
3
+ Datalayer config
4
+ """
2
5
  dataLayer: DatalayerConfig
3
6
  }
4
7
 
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@graphcommerce/google-datalayer",
3
3
  "homepage": "https://www.graphcommerce.org/",
4
4
  "repository": "github:graphcommerce-org/graphcommerce",
5
- "version": "8.1.0-canary.5",
5
+ "version": "8.1.0-canary.52",
6
6
  "sideEffects": false,
7
7
  "prettier": "@graphcommerce/prettier-config-pwa",
8
8
  "eslintConfig": {
@@ -12,14 +12,14 @@
12
12
  }
13
13
  },
14
14
  "peerDependencies": {
15
- "@graphcommerce/eslint-config-pwa": "^8.1.0-canary.5",
16
- "@graphcommerce/magento-cart": "^8.1.0-canary.5",
17
- "@graphcommerce/magento-cart-payment-method": "^8.1.0-canary.5",
18
- "@graphcommerce/magento-cart-shipping-method": "^8.1.0-canary.5",
19
- "@graphcommerce/magento-product": "^8.1.0-canary.5",
20
- "@graphcommerce/next-ui": "^8.1.0-canary.5",
21
- "@graphcommerce/prettier-config-pwa": "^8.1.0-canary.5",
22
- "@graphcommerce/typescript-config-pwa": "^8.1.0-canary.5",
15
+ "@graphcommerce/eslint-config-pwa": "^8.1.0-canary.52",
16
+ "@graphcommerce/magento-cart": "^8.1.0-canary.52",
17
+ "@graphcommerce/magento-cart-payment-method": "^8.1.0-canary.52",
18
+ "@graphcommerce/magento-cart-shipping-method": "^8.1.0-canary.52",
19
+ "@graphcommerce/magento-product": "^8.1.0-canary.52",
20
+ "@graphcommerce/next-ui": "^8.1.0-canary.52",
21
+ "@graphcommerce/prettier-config-pwa": "^8.1.0-canary.52",
22
+ "@graphcommerce/typescript-config-pwa": "^8.1.0-canary.52",
23
23
  "@mui/material": "^5.14.20",
24
24
  "next": "^14",
25
25
  "react": "^18.2.0",
@@ -15,7 +15,7 @@ export function GoogleDatalayerCartStartCheckoutLinkOrButton(
15
15
  <Prev
16
16
  {...rest}
17
17
  onStart={(e, cart) => {
18
- sendEvent('begin_checkout', cartToBeginCheckout(cart))
18
+ if (cart) sendEvent('begin_checkout', cartToBeginCheckout(cart))
19
19
  return onStart?.(e, cart)
20
20
  }}
21
21
  />
@@ -1,8 +1,7 @@
1
1
  import type { PaymentMethodContextProviderProps } from '@graphcommerce/magento-cart-payment-method'
2
2
  import type { PluginProps } from '@graphcommerce/next-config'
3
- import { purchase } from '../mapping/orderToPurchase'
4
- import { orderToPurchase } from '../mapping/orderToPurchase/orderToPurchase'
5
3
  import { sendEvent } from '../api/sendEvent'
4
+ import { orderToPurchase } from '../mapping/orderToPurchase/orderToPurchase'
6
5
 
7
6
  export const component = 'PaymentMethodContextProvider'
8
7
  export const exported = '@graphcommerce/magento-cart-payment-method'
@@ -1,15 +1,12 @@
1
- import { ProductListItem } from '@graphcommerce/magento-product'
1
+ import { ProductListItemProps } from '@graphcommerce/magento-product'
2
2
  import type { PluginProps } from '@graphcommerce/next-config'
3
3
  import { useEventCallback } from '@mui/material'
4
- import { ComponentProps } from 'react'
5
4
  import { useViewItemList } from '../components/DatalayerViewItemList'
6
5
 
7
6
  export const component = 'ProductListItem'
8
7
  export const exported = '@graphcommerce/magento-product'
9
8
 
10
- function GoogleDatalayerProductListItem(
11
- props: PluginProps<ComponentProps<typeof ProductListItem>>,
12
- ) {
9
+ function GoogleDatalayerProductListItem(props: PluginProps<ProductListItemProps>) {
13
10
  const { Prev, onClick, ...rest } = props
14
11
  const selectItem = useViewItemList()
15
12
 
@@ -1,32 +1,26 @@
1
- import type { RemoveItemFromCart } from '@graphcommerce/magento-cart-items'
2
- import type { ReactPlugin } from '@graphcommerce/next-config'
1
+ import type { useRemoveItemFromCart as useRemoveItemFromCartBase } from '@graphcommerce/magento-cart-items'
2
+ import type { FunctionPlugin, PluginConfig } from '@graphcommerce/next-config'
3
3
  import { sendEvent } from '../api/sendEvent'
4
4
  import { cartItemToRemoveFromCart } from '../mapping/cartItemToRemoveFromCart/cartToRemoveFromCart'
5
5
 
6
- export const component = 'RemoveItemFromCart'
7
- export const exported =
8
- '@graphcommerce/magento-cart-items/components/RemoveItemFromCart/RemoveItemFromCart'
9
-
10
- export const GoogleDatalayerRemoveItemFromCart: ReactPlugin<typeof RemoveItemFromCart> = (
11
- props,
12
- ) => {
13
- const { Prev, buttonProps } = props
14
-
15
- return (
16
- <Prev
17
- {...props}
18
- buttonProps={{
19
- ...buttonProps,
20
- onClick: (e) => {
21
- sendEvent(
22
- 'remove_from_cart',
23
- cartItemToRemoveFromCart({ __typename: 'SimpleCartItem', ...props }),
24
- )
25
- buttonProps?.onClick?.(e)
26
- },
27
- }}
28
- />
29
- )
6
+ export const config: PluginConfig = {
7
+ type: 'function',
8
+ module: '@graphcommerce/magento-cart-items',
30
9
  }
31
10
 
32
- export const Plugin = GoogleDatalayerRemoveItemFromCart
11
+ export const useRemoveItemFromCart: FunctionPlugin<typeof useRemoveItemFromCartBase> = (
12
+ usePrev,
13
+ props,
14
+ ) =>
15
+ usePrev({
16
+ ...props,
17
+ onComplete: (result, variables) => {
18
+ if (!result.errors) {
19
+ sendEvent(
20
+ 'remove_from_cart',
21
+ cartItemToRemoveFromCart({ ...props, __typename: 'SimpleCartItem' }),
22
+ )
23
+ }
24
+ return props.onComplete?.(result, variables)
25
+ },
26
+ })
@@ -1,7 +1,7 @@
1
- import type { ProductPageMeta } from '@graphcommerce/magento-product'
1
+ import type { ProductPageMetaProps } from '@graphcommerce/magento-product'
2
2
  import type { PluginProps } from '@graphcommerce/next-config'
3
3
  import { useMemoObject } from '@graphcommerce/next-ui'
4
- import React, { useEffect } from 'react'
4
+ import { useEffect } from 'react'
5
5
  import { sendEvent } from '../api/sendEvent'
6
6
  import { productToViewItem } from '../mapping/productToViewItem/productToViewItem'
7
7
 
@@ -9,7 +9,7 @@ export const component = 'ProductPageMeta'
9
9
  export const exported = '@graphcommerce/magento-product'
10
10
 
11
11
  /** When a product is added to the Cart, send a Google Analytics event */
12
- function GoogleDatalayerViewItem(props: PluginProps<React.ComponentProps<typeof ProductPageMeta>>) {
12
+ function GoogleDatalayerViewItem(props: PluginProps<ProductPageMetaProps>) {
13
13
  const { Prev, product } = props
14
14
 
15
15
  const viewItem = useMemoObject(productToViewItem(product))
@@ -1,19 +1,22 @@
1
1
  import type { PagesProps } from '@graphcommerce/framer-next-pages'
2
- import type { IfConfig, PluginProps } from '@graphcommerce/next-config'
2
+ import type { PluginConfig, PluginProps } from '@graphcommerce/next-config'
3
3
  import { useEventCallback } from '@mui/material'
4
4
  import { useEffect } from 'react'
5
5
  import { onCLS, onFCP, onFID, onINP, onLCP, onTTFB, Metric } from 'web-vitals/attribution'
6
6
  import { sendEvent } from '../api/sendEvent'
7
7
 
8
- export const component = 'FramerNextPages'
9
- export const exported = '@graphcommerce/framer-next-pages'
10
- export const ifConfig: IfConfig = 'dataLayer.coreWebVitals'
8
+ export const config: PluginConfig = {
9
+ type: 'component',
10
+ module: '@graphcommerce/framer-next-pages',
11
+ ifConfig: 'dataLayer.coreWebVitals',
12
+ }
11
13
 
12
- /** When a product is added to the Cart, send a Google Analytics event.
14
+ /**
15
+ * When a product is added to the Cart, send a Google Analytics event.
13
16
  *
14
17
  * Based on this information: https://github.com/GoogleChrome/web-vitals?tab=readme-ov-file#send-the-results-to-google-analytics
15
18
  */
16
- function GoogleDatalayerCoreWebVitals(props: PluginProps<PagesProps>) {
19
+ export function FramerNextPages(props: PluginProps<PagesProps>) {
17
20
  const { Prev, ...rest } = props
18
21
 
19
22
  const sendCoreWebVitals = useEventCallback((m: Metric, debug_target?: string | undefined) => {
@@ -36,5 +39,3 @@ function GoogleDatalayerCoreWebVitals(props: PluginProps<PagesProps>) {
36
39
 
37
40
  return <Prev {...rest} />
38
41
  }
39
-
40
- export const Plugin = GoogleDatalayerCoreWebVitals
@@ -1,30 +0,0 @@
1
- import type { RemoveItemFromCartFab as Original } from '@graphcommerce/magento-cart-items'
2
- import type { ReactPlugin } from '@graphcommerce/next-config'
3
- import { sendEvent } from '../api/sendEvent'
4
- import { cartItemToRemoveFromCart } from '../mapping/cartItemToRemoveFromCart/cartToRemoveFromCart'
5
-
6
- export const component = 'RemoveItemFromCartFab'
7
- export const exported =
8
- '@graphcommerce/magento-cart-items/components/RemoveItemFromCart/RemoveItemFromCartFab'
9
-
10
- export const GoogleDatalayerRemoveItemFromCartFab: ReactPlugin<typeof Original> = (props) => {
11
- const { Prev, fabProps } = props
12
-
13
- return (
14
- <Prev
15
- {...props}
16
- fabProps={{
17
- ...fabProps,
18
- onClick: (e) => {
19
- sendEvent(
20
- 'remove_from_cart',
21
- cartItemToRemoveFromCart({ __typename: 'SimpleCartItem', ...props }),
22
- )
23
- fabProps?.onClick?.(e)
24
- },
25
- }}
26
- />
27
- )
28
- }
29
-
30
- export const Plugin = GoogleDatalayerRemoveItemFromCartFab