@graphcommerce/google-datalayer 8.1.0-canary.8 → 9.0.0-canary.100

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.
Files changed (40) hide show
  1. package/CHANGELOG.md +205 -10
  2. package/Config.graphqls +3 -0
  3. package/api/googleEventNames.ts +116 -0
  4. package/api/sendEvent.ts +15 -7
  5. package/components/DatalayerViewItemList.tsx +55 -6
  6. package/mapping/cartItemToDatalayerItem/cartItemToDatalayerItem.ts +3 -2
  7. package/mapping/cartItemToRemoveFromCart/cartToRemoveFromCart.ts +2 -5
  8. package/mapping/cartToAddPaymentInfo/Cart_AddPaymentInfo.graphql +1 -1
  9. package/mapping/cartToAddPaymentInfo/cartToAddPaymentInfo.ts +10 -3
  10. package/mapping/cartToAddShippingInfo/Cart_AddShippingInfo.graphql +1 -1
  11. package/mapping/cartToAddShippingInfo/cartToAddShippingInfo.ts +14 -6
  12. package/mapping/cartToBeginCheckout/Cart_BeginCheckout.graphql +1 -1
  13. package/mapping/cartToBeginCheckout/cartToBeginCheckout.ts +7 -3
  14. package/mapping/cartToPurchase/Cart_PurchaseEvent.graphql +18 -0
  15. package/mapping/cartToPurchase/cartToPurchase.ts +28 -0
  16. package/mapping/cartToViewCart/Cart_ViewCart.graphql +8 -1
  17. package/mapping/cartToViewCart/cartToViewCart.ts +12 -3
  18. package/mapping/datalayerItemsToCurrencyValue/datalayerItemsToCurrencyValue.ts +9 -2
  19. package/mapping/productItemsToViewItemList/productItemsToViewItemList.ts +28 -6
  20. package/mapping/productToDatalayerItem/Product_DatalayerItem.graphql +1 -6
  21. package/mapping/productToDatalayerItem/productToDatalayerItem.ts +11 -4
  22. package/mapping/productToViewItem/productToViewItem.ts +13 -8
  23. package/package.json +12 -9
  24. package/plugins/GoogleDatalayerAddProductsToCartForm.tsx +13 -9
  25. package/plugins/GoogleDatalayerCartStartCheckout.tsx +9 -8
  26. package/plugins/GoogleDatalayerCartStartCheckoutLinkOrButton.tsx +8 -7
  27. package/plugins/GoogleDatalayerPaymentMethodButton.tsx +8 -7
  28. package/plugins/GoogleDatalayerPaymentMethodContextProvider.tsx +11 -8
  29. package/plugins/GoogleDatalayerProductListItem.tsx +6 -6
  30. package/plugins/GoogleDatalayerProductListItemsBase.tsx +15 -9
  31. package/plugins/GoogleDatalayerRemoveItemFromCart.tsx +21 -22
  32. package/plugins/GoogleDatalayerShippingMethodForm.tsx +10 -8
  33. package/plugins/{GoogleDatalayerUpdateItemQuantity.tsx → GoogleDatalayerUseRemoveItemFromCart.tsx} +9 -9
  34. package/plugins/GoogleDatalayerUseSignInForm.tsx +0 -0
  35. package/plugins/GoogleDatalayerViewItem.tsx +10 -9
  36. package/plugins/GoogleDatalayerWebVitals.tsx +2 -1
  37. package/mapping/cartToDatalayerItems/Cart_DatalayerItems.graphql +0 -11
  38. package/mapping/cartToDatalayerItems/cartToDatalayerItems.ts +0 -10
  39. package/mapping/orderToPurchase/orderToPurchase.ts +0 -17
  40. package/plugins/GoogleDatalayerRemoveItemFromCartFab.tsx +0 -29
@@ -1,21 +1,22 @@
1
1
  import type { ProductPageMetaProps } from '@graphcommerce/magento-product'
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 } from 'react'
5
- import { sendEvent } from '../api/sendEvent'
5
+ import { useSendEvent } from '../api/sendEvent'
6
6
  import { productToViewItem } from '../mapping/productToViewItem/productToViewItem'
7
7
 
8
- export const component = 'ProductPageMeta'
9
- export const exported = '@graphcommerce/magento-product'
8
+ export const config: PluginConfig = {
9
+ module: '@graphcommerce/magento-product',
10
+ type: 'component',
11
+ }
10
12
 
11
- /** When a product is added to the Cart, send a Google Analytics event */
12
- function GoogleDatalayerViewItem(props: PluginProps<ProductPageMetaProps>) {
13
+ /** When a product detail page is viewed, send a Google Analytics event */
14
+ export function ProductPageMeta(props: PluginProps<ProductPageMetaProps>) {
13
15
  const { Prev, product } = props
14
16
 
17
+ const sendEvent = useSendEvent()
15
18
  const viewItem = useMemoObject(productToViewItem(product))
16
- useEffect(() => sendEvent('view_item', viewItem), [viewItem])
19
+ useEffect(() => sendEvent('view_item', viewItem), [sendEvent, viewItem])
17
20
 
18
21
  return <Prev {...props} />
19
22
  }
20
-
21
- export const Plugin = GoogleDatalayerViewItem
@@ -3,7 +3,7 @@ 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
- import { sendEvent } from '../api/sendEvent'
6
+ import { useSendEvent } from '../api/sendEvent'
7
7
 
8
8
  export const config: PluginConfig = {
9
9
  type: 'component',
@@ -19,6 +19,7 @@ export const config: PluginConfig = {
19
19
  export function FramerNextPages(props: PluginProps<PagesProps>) {
20
20
  const { Prev, ...rest } = props
21
21
 
22
+ const sendEvent = useSendEvent()
22
23
  const sendCoreWebVitals = useEventCallback((m: Metric, debug_target?: string | undefined) => {
23
24
  sendEvent(`cwv_${m.name.toLowerCase()}`, {
24
25
  value: m.delta,
@@ -1,11 +0,0 @@
1
- fragment Cart_DatalayerItems on Cart {
2
- __typename
3
- items {
4
- ...CartItem_DatalayerItem
5
- }
6
- prices {
7
- subtotal_including_tax {
8
- currency
9
- }
10
- }
11
- }
@@ -1,10 +0,0 @@
1
- import { nonNullable } from '@graphcommerce/next-ui'
2
- import { cartItemToDatalayerItem } from '../cartItemToDatalayerItem/cartItemToDatalayerItem'
3
- import { datalayerItemsToCurrencyValue } from '../datalayerItemsToCurrencyValue/datalayerItemsToCurrencyValue'
4
- import { Cart_DatalayerItemsFragment } from './Cart_DatalayerItems.gql'
5
-
6
- export function cartToDatalayerItems<C extends Cart_DatalayerItemsFragment>(cart: C) {
7
- const items = cart.items?.filter(nonNullable).map(cartItemToDatalayerItem)
8
- if (!items) return {}
9
- return { ...datalayerItemsToCurrencyValue(items), items }
10
- }
@@ -1,17 +0,0 @@
1
- import { PaymentMethodContextFragment } from '@graphcommerce/magento-cart-payment-method/Api/PaymentMethodContext.gql'
2
- import { cartToDatalayerItems } from '../cartToDatalayerItems/cartToDatalayerItems'
3
-
4
- export function orderToPurchase<C extends PaymentMethodContextFragment>(
5
- orderNumber: string,
6
- cart: C | null | undefined,
7
- ) {
8
- if (!cart) return { transaction_id: orderNumber }
9
-
10
- return {
11
- transaction_id: orderNumber,
12
- coupon: cart.applied_coupons?.map((coupon) => coupon?.code).join(' '),
13
- payment_type: cart.selected_payment_method?.code,
14
- tax: cart.prices?.applied_taxes?.reduce((sum, tax) => sum + (tax?.amount?.value ?? 0), 0),
15
- ...cartToDatalayerItems(cart),
16
- }
17
- }
@@ -1,29 +0,0 @@
1
- import type { RemoveItemFromCartFabProps } from '@graphcommerce/magento-cart-items'
2
- import type { PluginConfig, PluginProps } from '@graphcommerce/next-config'
3
- import { sendEvent } from '../api/sendEvent'
4
- import { cartItemToRemoveFromCart } from '../mapping/cartItemToRemoveFromCart/cartToRemoveFromCart'
5
-
6
- export const config: PluginConfig = {
7
- type: 'component',
8
- module: '@graphcommerce/magento-cart-items',
9
- }
10
-
11
- export function RemoveItemFromCartFab(props: PluginProps<RemoveItemFromCartFabProps>) {
12
- const { Prev, fabProps } = props
13
-
14
- return (
15
- <Prev
16
- {...props}
17
- fabProps={{
18
- ...fabProps,
19
- onClick: (e) => {
20
- sendEvent(
21
- 'remove_from_cart',
22
- cartItemToRemoveFromCart({ __typename: 'SimpleCartItem', ...props }),
23
- )
24
- fabProps?.onClick?.(e)
25
- },
26
- }}
27
- />
28
- )
29
- }