@graphcommerce/google-datalayer 8.1.0-canary.9 → 9.0.0-canary.101
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 +205 -10
- package/Config.graphqls +3 -0
- package/api/googleEventNames.ts +116 -0
- package/api/sendEvent.ts +15 -7
- package/components/DatalayerViewItemList.tsx +55 -6
- package/mapping/cartItemToDatalayerItem/cartItemToDatalayerItem.ts +3 -2
- package/mapping/cartItemToRemoveFromCart/cartToRemoveFromCart.ts +2 -5
- package/mapping/cartToAddPaymentInfo/Cart_AddPaymentInfo.graphql +1 -1
- package/mapping/cartToAddPaymentInfo/cartToAddPaymentInfo.ts +10 -3
- package/mapping/cartToAddShippingInfo/Cart_AddShippingInfo.graphql +1 -1
- package/mapping/cartToAddShippingInfo/cartToAddShippingInfo.ts +14 -6
- package/mapping/cartToBeginCheckout/Cart_BeginCheckout.graphql +1 -1
- package/mapping/cartToBeginCheckout/cartToBeginCheckout.ts +7 -3
- package/mapping/cartToPurchase/Cart_PurchaseEvent.graphql +18 -0
- package/mapping/cartToPurchase/cartToPurchase.ts +28 -0
- package/mapping/cartToViewCart/Cart_ViewCart.graphql +8 -1
- package/mapping/cartToViewCart/cartToViewCart.ts +12 -3
- package/mapping/datalayerItemsToCurrencyValue/datalayerItemsToCurrencyValue.ts +9 -2
- package/mapping/productItemsToViewItemList/productItemsToViewItemList.ts +28 -6
- package/mapping/productToDatalayerItem/Product_DatalayerItem.graphql +1 -6
- package/mapping/productToDatalayerItem/productToDatalayerItem.ts +11 -4
- package/mapping/productToViewItem/productToViewItem.ts +13 -8
- package/package.json +13 -10
- package/plugins/GoogleDatalayerAddProductsToCartForm.tsx +13 -9
- package/plugins/GoogleDatalayerCartStartCheckout.tsx +9 -8
- package/plugins/GoogleDatalayerCartStartCheckoutLinkOrButton.tsx +8 -7
- package/plugins/GoogleDatalayerPaymentMethodButton.tsx +8 -7
- package/plugins/GoogleDatalayerPaymentMethodContextProvider.tsx +11 -8
- package/plugins/GoogleDatalayerProductListItem.tsx +6 -6
- package/plugins/GoogleDatalayerProductListItemsBase.tsx +15 -9
- package/plugins/GoogleDatalayerRemoveItemFromCart.tsx +21 -22
- package/plugins/GoogleDatalayerShippingMethodForm.tsx +10 -8
- package/plugins/{GoogleDatalayerUpdateItemQuantity.tsx → GoogleDatalayerUseRemoveItemFromCart.tsx} +9 -9
- package/plugins/GoogleDatalayerUseSignInForm.tsx +0 -0
- package/plugins/GoogleDatalayerViewItem.tsx +10 -9
- package/plugins/GoogleDatalayerWebVitals.tsx +4 -4
- package/mapping/cartToDatalayerItems/Cart_DatalayerItems.graphql +0 -11
- package/mapping/cartToDatalayerItems/cartToDatalayerItems.ts +0 -10
- package/mapping/orderToPurchase/orderToPurchase.ts +0 -17
- package/plugins/GoogleDatalayerRemoveItemFromCartFab.tsx +0 -29
|
@@ -1,6 +1,15 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { nonNullable } from '@graphcommerce/next-ui'
|
|
2
|
+
import { cartItemToDatalayerItem } from '../cartItemToDatalayerItem/cartItemToDatalayerItem'
|
|
3
|
+
import {
|
|
4
|
+
DataLayerCurrencyValue,
|
|
5
|
+
datalayerItemsToCurrencyValue,
|
|
6
|
+
} from '../datalayerItemsToCurrencyValue/datalayerItemsToCurrencyValue'
|
|
7
|
+
import { GoogleDatalayerItem } from '../productToDatalayerItem/productToDatalayerItem'
|
|
2
8
|
import { Cart_ViewCartFragment } from './Cart_ViewCart.gql'
|
|
3
9
|
|
|
4
|
-
export
|
|
5
|
-
|
|
10
|
+
export type ViewCart = DataLayerCurrencyValue & { items: GoogleDatalayerItem[] }
|
|
11
|
+
|
|
12
|
+
export function cartToViewCart<C extends Cart_ViewCartFragment>(cart: C): ViewCart {
|
|
13
|
+
const items = cart?.items?.filter(nonNullable).map(cartItemToDatalayerItem) ?? []
|
|
14
|
+
return { ...datalayerItemsToCurrencyValue(items), items }
|
|
6
15
|
}
|
|
@@ -1,8 +1,15 @@
|
|
|
1
1
|
import { GoogleDatalayerItem } from '../productToDatalayerItem/productToDatalayerItem'
|
|
2
2
|
|
|
3
|
-
export
|
|
3
|
+
export type DataLayerCurrencyValue = {
|
|
4
|
+
currency: string
|
|
5
|
+
value: number
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export function datalayerItemsToCurrencyValue(
|
|
9
|
+
items: GoogleDatalayerItem[],
|
|
10
|
+
): DataLayerCurrencyValue {
|
|
4
11
|
return {
|
|
5
|
-
currency: items[0]
|
|
12
|
+
currency: items[0]?.currency ?? '',
|
|
6
13
|
value: items.reduce((acc, item) => acc + (item.price ?? 0) * item.quantity, 0),
|
|
7
14
|
}
|
|
8
15
|
}
|
|
@@ -1,22 +1,44 @@
|
|
|
1
|
-
import { ProductListItemFragment } from '@graphcommerce/magento-product'
|
|
1
|
+
import { ProductFilterParams, ProductListItemFragment } from '@graphcommerce/magento-product'
|
|
2
2
|
import { nonNullable } from '@graphcommerce/next-ui'
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
GoogleDatalayerItem,
|
|
5
|
+
productToDatalayerItem,
|
|
6
|
+
} from '../productToDatalayerItem/productToDatalayerItem'
|
|
7
|
+
|
|
8
|
+
export type ViewItemList = {
|
|
9
|
+
item_list_id: string
|
|
10
|
+
item_list_name: string
|
|
11
|
+
items: GoogleDatalayerItem[]
|
|
12
|
+
filter_params?: ProductFilterParams | null
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export type SelectItem = {
|
|
16
|
+
item_list_id: string
|
|
17
|
+
item_list_name: string
|
|
18
|
+
items: GoogleDatalayerItem[]
|
|
19
|
+
filter_params?: ProductFilterParams | null
|
|
20
|
+
}
|
|
4
21
|
|
|
5
22
|
export function productItemsToViewItemList<P extends ProductListItemFragment>(
|
|
6
23
|
item_list_id: string,
|
|
7
24
|
item_list_name: string,
|
|
8
25
|
items: Array<P | null | undefined> | null | undefined,
|
|
9
|
-
|
|
26
|
+
filter_params: ProductFilterParams | null | undefined,
|
|
27
|
+
): ViewItemList {
|
|
10
28
|
return {
|
|
11
29
|
item_list_id,
|
|
12
30
|
item_list_name,
|
|
13
|
-
items: items?.filter(nonNullable)?.map(
|
|
31
|
+
items: (items ?? [])?.filter(nonNullable)?.map(productToDatalayerItem),
|
|
32
|
+
filter_params,
|
|
14
33
|
}
|
|
15
34
|
}
|
|
16
35
|
|
|
17
36
|
export function viewItemListToSelectItem(
|
|
18
37
|
viewItemList: ReturnType<typeof productItemsToViewItemList>,
|
|
19
38
|
itemId: string,
|
|
20
|
-
) {
|
|
21
|
-
return {
|
|
39
|
+
): SelectItem {
|
|
40
|
+
return {
|
|
41
|
+
...viewItemList,
|
|
42
|
+
items: viewItemList.items.filter((i) => i.item_id === itemId),
|
|
43
|
+
}
|
|
22
44
|
}
|
|
@@ -2,14 +2,18 @@ import { productPageCategory } from '@graphcommerce/magento-product'
|
|
|
2
2
|
import { nonNullable } from '@graphcommerce/next-ui'
|
|
3
3
|
import { Product_DatalayerItemFragment } from './Product_DatalayerItem.gql'
|
|
4
4
|
|
|
5
|
+
/**
|
|
6
|
+
* https://developers.google.com/tag-platform/gtagjs/reference/events#add_to_cart_item
|
|
7
|
+
*/
|
|
5
8
|
export type GoogleDatalayerItem = {
|
|
6
9
|
item_id: string
|
|
10
|
+
item_uid: string
|
|
7
11
|
item_name: string
|
|
8
12
|
affiliation?: string
|
|
9
13
|
coupon?: string
|
|
10
14
|
currency?: string
|
|
11
15
|
discount?: number
|
|
12
|
-
index
|
|
16
|
+
index: number
|
|
13
17
|
item_brand?: string
|
|
14
18
|
item_category?: string
|
|
15
19
|
item_category2?: string
|
|
@@ -20,27 +24,30 @@ export type GoogleDatalayerItem = {
|
|
|
20
24
|
item_list_name?: string
|
|
21
25
|
item_variant?: string
|
|
22
26
|
location_id?: string
|
|
23
|
-
price
|
|
27
|
+
price: number
|
|
24
28
|
quantity: number
|
|
25
29
|
}
|
|
26
30
|
|
|
27
31
|
export function productToDatalayerItem<P extends Product_DatalayerItemFragment>(
|
|
28
32
|
item: P,
|
|
33
|
+
index: number,
|
|
29
34
|
): GoogleDatalayerItem {
|
|
30
35
|
const category = productPageCategory(item)
|
|
31
36
|
const item_categories = Object.fromEntries(
|
|
32
37
|
[...(category?.breadcrumbs?.map((b) => b?.category_name) ?? []), category?.name]
|
|
33
38
|
.filter(nonNullable)
|
|
34
|
-
.map((name,
|
|
39
|
+
.map((name, idx) => [`item_category${idx > 0 ? idx + 1 : ''}`, name]),
|
|
35
40
|
)
|
|
36
41
|
|
|
37
42
|
return {
|
|
38
43
|
item_id: item.sku ?? '',
|
|
44
|
+
item_uid: item.uid,
|
|
39
45
|
item_name: item.name ?? '',
|
|
40
|
-
price: item.price_range?.minimum_price.final_price.value ??
|
|
46
|
+
price: item.price_range?.minimum_price.final_price.value ?? 0,
|
|
41
47
|
currency: item.price_range?.minimum_price.final_price.currency ?? undefined,
|
|
42
48
|
discount: item.price_range?.minimum_price.discount?.amount_off ?? undefined,
|
|
43
49
|
quantity: 1,
|
|
50
|
+
index,
|
|
44
51
|
...item_categories,
|
|
45
52
|
}
|
|
46
53
|
}
|
|
@@ -1,11 +1,16 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import {
|
|
2
|
+
DataLayerCurrencyValue,
|
|
3
|
+
datalayerItemsToCurrencyValue,
|
|
4
|
+
} from '../datalayerItemsToCurrencyValue/datalayerItemsToCurrencyValue'
|
|
5
|
+
import {
|
|
6
|
+
GoogleDatalayerItem,
|
|
7
|
+
productToDatalayerItem,
|
|
8
|
+
} from '../productToDatalayerItem/productToDatalayerItem'
|
|
3
9
|
import { Product_ViewItemFragment } from './Product_ViewItem.gql'
|
|
4
10
|
|
|
5
|
-
export
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
}
|
|
11
|
+
export type ViewItem = { items: GoogleDatalayerItem[] } & DataLayerCurrencyValue
|
|
12
|
+
|
|
13
|
+
export function productToViewItem<C extends Product_ViewItemFragment>(product: C): ViewItem {
|
|
14
|
+
const items = [productToDatalayerItem(product, 0)]
|
|
15
|
+
return { ...datalayerItemsToCurrencyValue(items), items }
|
|
11
16
|
}
|
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": "
|
|
5
|
+
"version": "9.0.0-canary.101",
|
|
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": "^
|
|
16
|
-
"@graphcommerce/magento-cart": "^
|
|
17
|
-
"@graphcommerce/magento-cart-payment-method": "^
|
|
18
|
-
"@graphcommerce/magento-cart-shipping-method": "^
|
|
19
|
-
"@graphcommerce/magento-product": "^
|
|
20
|
-
"@graphcommerce/next-ui": "^
|
|
21
|
-
"@graphcommerce/prettier-config-pwa": "^
|
|
22
|
-
"@graphcommerce/typescript-config-pwa": "^
|
|
15
|
+
"@graphcommerce/eslint-config-pwa": "^9.0.0-canary.101",
|
|
16
|
+
"@graphcommerce/magento-cart": "^9.0.0-canary.101",
|
|
17
|
+
"@graphcommerce/magento-cart-payment-method": "^9.0.0-canary.101",
|
|
18
|
+
"@graphcommerce/magento-cart-shipping-method": "^9.0.0-canary.101",
|
|
19
|
+
"@graphcommerce/magento-product": "^9.0.0-canary.101",
|
|
20
|
+
"@graphcommerce/next-ui": "^9.0.0-canary.101",
|
|
21
|
+
"@graphcommerce/prettier-config-pwa": "^9.0.0-canary.101",
|
|
22
|
+
"@graphcommerce/typescript-config-pwa": "^9.0.0-canary.101",
|
|
23
23
|
"@mui/material": "^5.14.20",
|
|
24
24
|
"next": "^14",
|
|
25
25
|
"react": "^18.2.0",
|
|
@@ -37,9 +37,12 @@
|
|
|
37
37
|
},
|
|
38
38
|
"@graphcommerce/magento-product": {
|
|
39
39
|
"optional": true
|
|
40
|
+
},
|
|
41
|
+
"@graphcommerce/magento-product-configurable": {
|
|
42
|
+
"optional": true
|
|
40
43
|
}
|
|
41
44
|
},
|
|
42
45
|
"dependencies": {
|
|
43
|
-
"web-vitals": "^
|
|
46
|
+
"web-vitals": "^4.2.3"
|
|
44
47
|
}
|
|
45
48
|
}
|
|
@@ -3,19 +3,22 @@ import {
|
|
|
3
3
|
findAddedItems,
|
|
4
4
|
toUserErrors,
|
|
5
5
|
} from '@graphcommerce/magento-product'
|
|
6
|
-
import type { PluginProps } from '@graphcommerce/next-config'
|
|
6
|
+
import type { PluginConfig, PluginProps } from '@graphcommerce/next-config'
|
|
7
7
|
import { nonNullable } from '@graphcommerce/next-ui'
|
|
8
|
-
import {
|
|
8
|
+
import { useSendEvent } from '../api/sendEvent'
|
|
9
9
|
import { cartItemToDatalayerItem } from '../mapping/cartItemToDatalayerItem/cartItemToDatalayerItem'
|
|
10
10
|
import { datalayerItemsToCurrencyValue } from '../mapping/datalayerItemsToCurrencyValue/datalayerItemsToCurrencyValue'
|
|
11
11
|
|
|
12
|
-
export const
|
|
13
|
-
|
|
12
|
+
export const config: PluginConfig = {
|
|
13
|
+
module: '@graphcommerce/magento-product',
|
|
14
|
+
type: 'component',
|
|
15
|
+
}
|
|
14
16
|
|
|
15
17
|
/** When a product is added to the Cart, send a Google Analytics event */
|
|
16
|
-
function
|
|
18
|
+
export function AddProductsToCartForm(props: PluginProps<AddProductsToCartFormProps>) {
|
|
17
19
|
const { Prev, onComplete, ...rest } = props
|
|
18
20
|
|
|
21
|
+
const sendEvent = useSendEvent()
|
|
19
22
|
return (
|
|
20
23
|
<Prev
|
|
21
24
|
{...rest}
|
|
@@ -24,9 +27,12 @@ function GoogleDatalayerAddProductsToCartForm(props: PluginProps<AddProductsToCa
|
|
|
24
27
|
const addedItems = findAddedItems(data, variables)
|
|
25
28
|
|
|
26
29
|
const items = addedItems
|
|
27
|
-
.map(({ itemVariable, itemInCart }) => {
|
|
30
|
+
.map(({ itemVariable, itemInCart }, index) => {
|
|
28
31
|
if (!itemInCart) return null
|
|
29
|
-
return {
|
|
32
|
+
return {
|
|
33
|
+
...cartItemToDatalayerItem(itemInCart, index),
|
|
34
|
+
quantity: itemVariable.quantity,
|
|
35
|
+
}
|
|
30
36
|
})
|
|
31
37
|
.filter(nonNullable)
|
|
32
38
|
|
|
@@ -48,5 +54,3 @@ function GoogleDatalayerAddProductsToCartForm(props: PluginProps<AddProductsToCa
|
|
|
48
54
|
/>
|
|
49
55
|
)
|
|
50
56
|
}
|
|
51
|
-
|
|
52
|
-
export const Plugin = GoogleDatalayerAddProductsToCartForm
|
|
@@ -1,25 +1,28 @@
|
|
|
1
1
|
import { CartStartCheckoutProps } from '@graphcommerce/magento-cart'
|
|
2
|
-
import type { PluginProps } from '@graphcommerce/next-config'
|
|
2
|
+
import type { PluginConfig, PluginProps } from '@graphcommerce/next-config'
|
|
3
3
|
import { useMemoObject } from '@graphcommerce/next-ui'
|
|
4
4
|
import { useEffect, useRef } from 'react'
|
|
5
|
-
import {
|
|
5
|
+
import { useSendEvent } from '../api/sendEvent'
|
|
6
6
|
import { cartToBeginCheckout } from '../mapping/cartToBeginCheckout/cartToBeginCheckout'
|
|
7
7
|
import { cartToViewCart } from '../mapping/cartToViewCart/cartToViewCart'
|
|
8
8
|
|
|
9
|
-
export const
|
|
10
|
-
|
|
9
|
+
export const config: PluginConfig = {
|
|
10
|
+
module: '@graphcommerce/magento-cart',
|
|
11
|
+
type: 'component',
|
|
12
|
+
}
|
|
11
13
|
|
|
12
|
-
export function
|
|
14
|
+
export function CartStartCheckout(props: PluginProps<CartStartCheckoutProps>) {
|
|
13
15
|
const { Prev, onStart, ...rest } = props
|
|
14
16
|
|
|
15
17
|
const send = useRef(false)
|
|
18
|
+
const sendEvent = useSendEvent()
|
|
16
19
|
const viewCart = useMemoObject(cartToViewCart({ __typename: 'Cart', ...props }))
|
|
17
20
|
useEffect(() => {
|
|
18
21
|
if (!send.current) {
|
|
19
22
|
sendEvent('view_cart', viewCart)
|
|
20
23
|
send.current = true
|
|
21
24
|
}
|
|
22
|
-
}, [viewCart])
|
|
25
|
+
}, [sendEvent, viewCart])
|
|
23
26
|
|
|
24
27
|
return (
|
|
25
28
|
<Prev
|
|
@@ -31,5 +34,3 @@ export function GoogleDatalayerCartStartCheckout(props: PluginProps<CartStartChe
|
|
|
31
34
|
/>
|
|
32
35
|
)
|
|
33
36
|
}
|
|
34
|
-
|
|
35
|
-
export const Plugin = GoogleDatalayerCartStartCheckout
|
|
@@ -1,16 +1,19 @@
|
|
|
1
1
|
import { CartStartCheckoutLinkOrButtonProps } from '@graphcommerce/magento-cart'
|
|
2
|
-
import type { PluginProps } from '@graphcommerce/next-config'
|
|
3
|
-
import {
|
|
2
|
+
import type { PluginConfig, PluginProps } from '@graphcommerce/next-config'
|
|
3
|
+
import { useSendEvent } from '../api/sendEvent'
|
|
4
4
|
import { cartToBeginCheckout } from '../mapping/cartToBeginCheckout/cartToBeginCheckout'
|
|
5
5
|
|
|
6
|
-
export const
|
|
7
|
-
|
|
6
|
+
export const config: PluginConfig = {
|
|
7
|
+
module: '@graphcommerce/magento-cart',
|
|
8
|
+
type: 'component',
|
|
9
|
+
}
|
|
8
10
|
|
|
9
|
-
export function
|
|
11
|
+
export function CartStartCheckoutLinkOrButton(
|
|
10
12
|
props: PluginProps<CartStartCheckoutLinkOrButtonProps>,
|
|
11
13
|
) {
|
|
12
14
|
const { Prev, onStart, ...rest } = props
|
|
13
15
|
|
|
16
|
+
const sendEvent = useSendEvent()
|
|
14
17
|
return (
|
|
15
18
|
<Prev
|
|
16
19
|
{...rest}
|
|
@@ -21,5 +24,3 @@ export function GoogleDatalayerCartStartCheckoutLinkOrButton(
|
|
|
21
24
|
/>
|
|
22
25
|
)
|
|
23
26
|
}
|
|
24
|
-
|
|
25
|
-
export const Plugin = GoogleDatalayerCartStartCheckoutLinkOrButton
|
|
@@ -1,17 +1,20 @@
|
|
|
1
1
|
import { useCartQuery } from '@graphcommerce/magento-cart'
|
|
2
2
|
import { PaymentMethodButtonProps } from '@graphcommerce/magento-cart-payment-method'
|
|
3
3
|
import { GetPaymentMethodContextDocument } from '@graphcommerce/magento-cart-payment-method/PaymentMethodContext/GetPaymentMethodContext.gql'
|
|
4
|
-
import type { PluginProps } from '@graphcommerce/next-config'
|
|
5
|
-
import {
|
|
4
|
+
import type { PluginConfig, PluginProps } from '@graphcommerce/next-config'
|
|
5
|
+
import { useSendEvent } from '../api/sendEvent'
|
|
6
6
|
import { cartToAddPaymentInfo } from '../mapping/cartToAddPaymentInfo/cartToAddPaymentInfo'
|
|
7
7
|
|
|
8
|
-
export const
|
|
9
|
-
|
|
8
|
+
export const config: PluginConfig = {
|
|
9
|
+
module: '@graphcommerce/magento-cart-payment-method',
|
|
10
|
+
type: 'component',
|
|
11
|
+
}
|
|
10
12
|
|
|
11
|
-
function
|
|
13
|
+
export function PaymentMethodButton(props: PluginProps<PaymentMethodButtonProps>) {
|
|
12
14
|
const { Prev, onSubmitSuccessful, ...rest } = props
|
|
13
15
|
const methodContext = useCartQuery(GetPaymentMethodContextDocument)
|
|
14
16
|
|
|
17
|
+
const sendEvent = useSendEvent()
|
|
15
18
|
return (
|
|
16
19
|
<Prev
|
|
17
20
|
{...rest}
|
|
@@ -24,5 +27,3 @@ function GoogleDatalayerPaymentMethodButton(props: PluginProps<PaymentMethodButt
|
|
|
24
27
|
/>
|
|
25
28
|
)
|
|
26
29
|
}
|
|
27
|
-
|
|
28
|
-
export const Plugin = GoogleDatalayerPaymentMethodButton
|
|
@@ -1,23 +1,26 @@
|
|
|
1
1
|
import type { PaymentMethodContextProviderProps } from '@graphcommerce/magento-cart-payment-method'
|
|
2
|
-
import type { PluginProps } from '@graphcommerce/next-config'
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
2
|
+
import type { PluginConfig, PluginProps } from '@graphcommerce/next-config'
|
|
3
|
+
import { useSendEvent } from '../api/sendEvent'
|
|
4
|
+
import { cartToPurchase } from '../mapping/cartToPurchase/cartToPurchase'
|
|
5
5
|
|
|
6
|
-
export const
|
|
7
|
-
|
|
6
|
+
export const config: PluginConfig = {
|
|
7
|
+
module: '@graphcommerce/magento-cart-payment-method',
|
|
8
|
+
type: 'component',
|
|
9
|
+
}
|
|
8
10
|
|
|
9
|
-
function
|
|
11
|
+
export function PaymentMethodContextProvider(
|
|
10
12
|
props: PluginProps<PaymentMethodContextProviderProps>,
|
|
11
13
|
) {
|
|
12
14
|
const { Prev, onSuccess, ...rest } = props
|
|
15
|
+
|
|
16
|
+
const sendEvent = useSendEvent()
|
|
13
17
|
return (
|
|
14
18
|
<Prev
|
|
15
19
|
{...rest}
|
|
16
20
|
onSuccess={(orderNumber, cart) => {
|
|
17
|
-
sendEvent('purchase',
|
|
21
|
+
sendEvent('purchase', cartToPurchase(orderNumber, cart))
|
|
18
22
|
return onSuccess?.(orderNumber, cart)
|
|
19
23
|
}}
|
|
20
24
|
/>
|
|
21
25
|
)
|
|
22
26
|
}
|
|
23
|
-
export const Plugin = GoogleDatalayerPaymentMethodContextProvider
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import { ProductListItemProps } from '@graphcommerce/magento-product'
|
|
2
|
-
import type { PluginProps } from '@graphcommerce/next-config'
|
|
2
|
+
import type { PluginConfig, PluginProps } from '@graphcommerce/next-config'
|
|
3
3
|
import { useEventCallback } from '@mui/material'
|
|
4
4
|
import { useViewItemList } from '../components/DatalayerViewItemList'
|
|
5
5
|
|
|
6
|
-
export const
|
|
7
|
-
|
|
6
|
+
export const config: PluginConfig = {
|
|
7
|
+
module: '@graphcommerce/magento-product',
|
|
8
|
+
type: 'component',
|
|
9
|
+
}
|
|
8
10
|
|
|
9
|
-
function
|
|
11
|
+
export function ProductListItem(props: PluginProps<ProductListItemProps>) {
|
|
10
12
|
const { Prev, onClick, ...rest } = props
|
|
11
13
|
const selectItem = useViewItemList()
|
|
12
14
|
|
|
@@ -20,5 +22,3 @@ function GoogleDatalayerProductListItem(props: PluginProps<ProductListItemProps>
|
|
|
20
22
|
/>
|
|
21
23
|
)
|
|
22
24
|
}
|
|
23
|
-
|
|
24
|
-
export const Plugin = GoogleDatalayerProductListItem
|
|
@@ -1,17 +1,23 @@
|
|
|
1
1
|
import type { ProductItemsGridProps } from '@graphcommerce/magento-product'
|
|
2
|
-
import type { PluginProps } from '@graphcommerce/next-config'
|
|
2
|
+
import type { PluginConfig, PluginProps } from '@graphcommerce/next-config'
|
|
3
|
+
import { useForkRef } from '@mui/material'
|
|
4
|
+
import { useRef } from 'react'
|
|
3
5
|
import { DatalayerViewItemList } from '../components/DatalayerViewItemList'
|
|
4
6
|
|
|
5
|
-
export const
|
|
6
|
-
|
|
7
|
+
export const config: PluginConfig = {
|
|
8
|
+
module: '@graphcommerce/magento-product',
|
|
9
|
+
type: 'component',
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function ProductListItemsBase(props: PluginProps<ProductItemsGridProps>) {
|
|
13
|
+
const { Prev, containerRef, ...rest } = props
|
|
14
|
+
|
|
15
|
+
const internalRef = useRef<HTMLDivElement>(null)
|
|
16
|
+
const ref = useForkRef(containerRef, internalRef)
|
|
7
17
|
|
|
8
|
-
export function GoogleDatalayerProductListItemsBase(props: PluginProps<ProductItemsGridProps>) {
|
|
9
|
-
const { Prev, ...rest } = props
|
|
10
18
|
return (
|
|
11
|
-
<DatalayerViewItemList {...rest}>
|
|
12
|
-
<Prev {...rest} />
|
|
19
|
+
<DatalayerViewItemList {...rest} containerRef={internalRef}>
|
|
20
|
+
<Prev {...rest} containerRef={ref} />
|
|
13
21
|
</DatalayerViewItemList>
|
|
14
22
|
)
|
|
15
23
|
}
|
|
16
|
-
|
|
17
|
-
export const Plugin = GoogleDatalayerProductListItemsBase
|
|
@@ -1,29 +1,28 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
3
|
-
import {
|
|
1
|
+
import type { useRemoveItemFromCart as useRemoveItemFromCartBase } from '@graphcommerce/magento-cart-items'
|
|
2
|
+
import type { FunctionPlugin, PluginConfig } from '@graphcommerce/next-config'
|
|
3
|
+
import { useSendEvent } from '../api/sendEvent'
|
|
4
4
|
import { cartItemToRemoveFromCart } from '../mapping/cartItemToRemoveFromCart/cartToRemoveFromCart'
|
|
5
5
|
|
|
6
6
|
export const config: PluginConfig = {
|
|
7
|
-
type: '
|
|
7
|
+
type: 'function',
|
|
8
8
|
module: '@graphcommerce/magento-cart-items',
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
-
export
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
)
|
|
11
|
+
export const useRemoveItemFromCart: FunctionPlugin<typeof useRemoveItemFromCartBase> = (
|
|
12
|
+
usePrev,
|
|
13
|
+
props,
|
|
14
|
+
) => {
|
|
15
|
+
const sendEvent = useSendEvent()
|
|
16
|
+
return usePrev({
|
|
17
|
+
...props,
|
|
18
|
+
onComplete: (result, variables) => {
|
|
19
|
+
if (!result.errors) {
|
|
20
|
+
sendEvent(
|
|
21
|
+
'remove_from_cart',
|
|
22
|
+
cartItemToRemoveFromCart({ ...props, __typename: 'SimpleCartItem' }),
|
|
23
|
+
)
|
|
24
|
+
}
|
|
25
|
+
return props.onComplete?.(result, variables)
|
|
26
|
+
},
|
|
27
|
+
})
|
|
29
28
|
}
|
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
import { ShippingMethodFormProps } from '@graphcommerce/magento-cart-shipping-method'
|
|
2
|
-
import type { PluginProps } from '@graphcommerce/next-config'
|
|
3
|
-
import {
|
|
2
|
+
import type { PluginConfig, PluginProps } from '@graphcommerce/next-config'
|
|
3
|
+
import { useSendEvent } from '../api/sendEvent'
|
|
4
4
|
import { cartToAddShippingInfo } from '../mapping/cartToAddShippingInfo/cartToAddShippingInfo'
|
|
5
5
|
|
|
6
|
-
export const
|
|
7
|
-
|
|
6
|
+
export const config: PluginConfig = {
|
|
7
|
+
module: '@graphcommerce/magento-cart-shipping-method',
|
|
8
|
+
type: 'component',
|
|
9
|
+
}
|
|
8
10
|
|
|
9
|
-
export function
|
|
11
|
+
export function ShippingMethodForm(props: PluginProps<ShippingMethodFormProps>) {
|
|
10
12
|
const { Prev, onComplete, ...rest } = props
|
|
13
|
+
|
|
14
|
+
const sendEvent = useSendEvent()
|
|
11
15
|
return (
|
|
12
16
|
<Prev
|
|
13
17
|
{...rest}
|
|
@@ -15,7 +19,7 @@ export function GoogleDatalayerShippingMethodForm(props: PluginProps<ShippingMet
|
|
|
15
19
|
if (result.data?.setShippingMethodsOnCart?.cart) {
|
|
16
20
|
sendEvent(
|
|
17
21
|
'add_shipping_info',
|
|
18
|
-
cartToAddShippingInfo(result.data
|
|
22
|
+
cartToAddShippingInfo(result.data.setShippingMethodsOnCart.cart),
|
|
19
23
|
)
|
|
20
24
|
}
|
|
21
25
|
|
|
@@ -24,5 +28,3 @@ export function GoogleDatalayerShippingMethodForm(props: PluginProps<ShippingMet
|
|
|
24
28
|
/>
|
|
25
29
|
)
|
|
26
30
|
}
|
|
27
|
-
|
|
28
|
-
export const Plugin = GoogleDatalayerShippingMethodForm
|
package/plugins/{GoogleDatalayerUpdateItemQuantity.tsx → GoogleDatalayerUseRemoveItemFromCart.tsx}
RENAMED
|
@@ -1,20 +1,22 @@
|
|
|
1
1
|
import type { UpdateItemQuantityProps } from '@graphcommerce/magento-cart-items'
|
|
2
|
-
import type { PluginProps } from '@graphcommerce/next-config'
|
|
3
|
-
import {
|
|
2
|
+
import type { PluginConfig, PluginProps } from '@graphcommerce/next-config'
|
|
3
|
+
import { useSendEvent } from '../api/sendEvent'
|
|
4
4
|
import { cartItemToDatalayerItem } from '../mapping/cartItemToDatalayerItem/cartItemToDatalayerItem'
|
|
5
5
|
import { datalayerItemsToCurrencyValue } from '../mapping/datalayerItemsToCurrencyValue/datalayerItemsToCurrencyValue'
|
|
6
6
|
|
|
7
|
-
export const
|
|
8
|
-
|
|
9
|
-
'
|
|
7
|
+
export const config: PluginConfig = {
|
|
8
|
+
module: '@graphcommerce/magento-cart-items',
|
|
9
|
+
type: 'component',
|
|
10
|
+
}
|
|
10
11
|
|
|
11
12
|
/**
|
|
12
13
|
* When a product is added to the Cart, by using the + button on cart page, send a Google Analytics
|
|
13
14
|
* event
|
|
14
15
|
*/
|
|
15
|
-
function
|
|
16
|
+
export function UpdateItemQuantity(props: PluginProps<UpdateItemQuantityProps>) {
|
|
16
17
|
const { Prev, formOptions, quantity, ...rest } = props
|
|
17
18
|
|
|
19
|
+
const sendEvent = useSendEvent()
|
|
18
20
|
return (
|
|
19
21
|
<Prev
|
|
20
22
|
{...rest}
|
|
@@ -32,7 +34,7 @@ function GoogleDatalayerUpdateItemQuantity(props: PluginProps<UpdateItemQuantity
|
|
|
32
34
|
|
|
33
35
|
if (!itemInCart?.quantity || diffQuantity === 0) return original
|
|
34
36
|
|
|
35
|
-
const items = [{ ...cartItemToDatalayerItem(itemInCart), quantity: absQuantity }]
|
|
37
|
+
const items = [{ ...cartItemToDatalayerItem(itemInCart, 0), quantity: absQuantity }]
|
|
36
38
|
sendEvent(diffQuantity < 0 ? 'remove_from_cart' : 'add_to_cart', {
|
|
37
39
|
...datalayerItemsToCurrencyValue(items),
|
|
38
40
|
items,
|
|
@@ -44,5 +46,3 @@ function GoogleDatalayerUpdateItemQuantity(props: PluginProps<UpdateItemQuantity
|
|
|
44
46
|
/>
|
|
45
47
|
)
|
|
46
48
|
}
|
|
47
|
-
|
|
48
|
-
export const Plugin = GoogleDatalayerUpdateItemQuantity
|
|
File without changes
|