@graphcommerce/googleanalytics 3.0.9 → 3.1.0-canary.10
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 +29 -1
- package/components/GoogleAnalyticsScript.tsx +0 -3
- package/events/gtagAddShippingInfo/GtagAddShippingInfo.graphql +1 -1
- package/events/gtagAddShippingInfo/gtagAddShippingInfo.ts +17 -20
- package/events/gtagAddToCart/gtagAddToCart.ts +1 -1
- package/package.json +8 -4
- package/plugins/GaAddProductsToCartForm.tsx +22 -0
- package/plugins/GaCartStartCheckout.tsx +21 -0
- package/plugins/GaCartStartCheckoutLinkOrButton.tsx +23 -0
- package/plugins/GaFramerNextPages.tsx +34 -0
- package/plugins/GaPaymentMethodButton.tsx +25 -0
- package/plugins/GaPaymentMethodContextProvider.tsx +19 -0
- package/plugins/GaProductListItemsBase.tsx +25 -0
- package/plugins/GaShippingMethodForm.tsx +23 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,34 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
-
## 3.0.
|
|
3
|
+
## 3.1.0-canary.10
|
|
4
|
+
|
|
5
|
+
## 3.1.0-canary.9
|
|
6
|
+
|
|
7
|
+
## 3.1.0-canary.8
|
|
8
|
+
|
|
9
|
+
## 3.1.0-canary.7
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- [#1738](https://github.com/graphcommerce-org/graphcommerce/pull/1738) [`52882a63e`](https://github.com/graphcommerce-org/graphcommerce/commit/52882a63e96c0d3ba9641c3714d288fa4f420c82) - Do not forward the Prev prop in plugins ([@paales](https://github.com/paales))
|
|
14
|
+
|
|
15
|
+
## 3.1.0-canary.6
|
|
16
|
+
|
|
17
|
+
## 3.1.0-canary.5
|
|
18
|
+
|
|
19
|
+
## 3.1.0-canary.4
|
|
20
|
+
|
|
21
|
+
### Minor Changes
|
|
22
|
+
|
|
23
|
+
- [#1733](https://github.com/graphcommerce-org/graphcommerce/pull/1733) [`85afcf4d0`](https://github.com/graphcommerce-org/graphcommerce/commit/85afcf4d011701f4b80e59e2b2b52a2e1f99a655) - Google Analytics now uses the new plugin system ([@paales](https://github.com/paales))
|
|
24
|
+
|
|
25
|
+
## 3.0.9-canary.3
|
|
26
|
+
|
|
27
|
+
## 3.0.9-canary.2
|
|
28
|
+
|
|
29
|
+
## 3.0.9-canary.1
|
|
30
|
+
|
|
31
|
+
## 3.0.9-canary.0
|
|
4
32
|
|
|
5
33
|
## 3.0.8
|
|
6
34
|
|
|
@@ -3,9 +3,6 @@ import Script from 'next/script'
|
|
|
3
3
|
export function GoogleAnalyticsScript() {
|
|
4
4
|
const id = process.env.NEXT_PUBLIC_GOOGLE_ANALYTICS
|
|
5
5
|
|
|
6
|
-
if (process.env.NODE_ENV !== 'production' && !id)
|
|
7
|
-
console.warn('[@graphcommerce/googletagmanager]: NEXT_PUBLIC_GOOGLE_ANALYTICS not found')
|
|
8
|
-
|
|
9
6
|
if (!id) return null
|
|
10
7
|
|
|
11
8
|
return (
|
|
@@ -1,24 +1,21 @@
|
|
|
1
1
|
import { GtagAddShippingInfoFragment } from './GtagAddShippingInfo.gql'
|
|
2
2
|
|
|
3
3
|
export function gtagAddShippingInfo<C extends GtagAddShippingInfoFragment>(cart?: C | null) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
discount
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
})),
|
|
22
|
-
})
|
|
23
|
-
}
|
|
4
|
+
globalThis.gtag?.('event', 'add_shipping_info', {
|
|
5
|
+
currency: cart?.prices?.grand_total?.currency,
|
|
6
|
+
value: cart?.prices?.grand_total?.value,
|
|
7
|
+
coupon: cart?.applied_coupons?.map((coupon) => coupon?.code),
|
|
8
|
+
items: cart?.items?.map((item) => ({
|
|
9
|
+
item_id: item?.product.sku,
|
|
10
|
+
item_name: item?.product.name,
|
|
11
|
+
currency: item?.prices?.price.currency,
|
|
12
|
+
discount: item?.prices?.discounts?.reduce(
|
|
13
|
+
(sum, discount) => sum + (discount?.amount?.value ?? 0),
|
|
14
|
+
0,
|
|
15
|
+
),
|
|
16
|
+
item_variant: item?.__typename === 'ConfigurableCartItem' ? item.configured_variant.sku : '',
|
|
17
|
+
price: item?.prices?.price.value,
|
|
18
|
+
quantity: item?.quantity,
|
|
19
|
+
})),
|
|
20
|
+
})
|
|
24
21
|
}
|
|
@@ -8,7 +8,7 @@ import { GtagAddToCartFragment } from './GtagAddToCart.gql'
|
|
|
8
8
|
// @todo add types
|
|
9
9
|
// @todo some thing still needs to be done for configurables and bundles as you can have multiple items of the same SKU in your cart, but with different configurations/prices
|
|
10
10
|
// F.E. 'sock-red' has 2 variants, 'sock-red:small' (€ 5) and 'sock-red:large' (€ 7,50). At this time we dont know the value of the item added if multiple variants are added
|
|
11
|
-
export const gtagAddToCart = (
|
|
11
|
+
export const gtagAddToCart = async (
|
|
12
12
|
result: FetchResult<AddProductsToCartMutation>,
|
|
13
13
|
variables: AddProductsToCartMutationVariables,
|
|
14
14
|
) => {
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@graphcommerce/googleanalytics",
|
|
3
3
|
"homepage": "https://www.graphcommerce.org/",
|
|
4
4
|
"repository": "github:graphcommerce-org/graphcommerce",
|
|
5
|
-
"version": "3.0.
|
|
5
|
+
"version": "3.1.0-canary.10",
|
|
6
6
|
"sideEffects": false,
|
|
7
7
|
"prettier": "@graphcommerce/prettier-config-pwa",
|
|
8
8
|
"eslintConfig": {
|
|
@@ -12,9 +12,13 @@
|
|
|
12
12
|
}
|
|
13
13
|
},
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@graphcommerce/graphql-mesh": "4.
|
|
16
|
-
"@graphcommerce/magento-
|
|
17
|
-
"@graphcommerce/
|
|
15
|
+
"@graphcommerce/graphql-mesh": "4.31.0-canary.6",
|
|
16
|
+
"@graphcommerce/magento-cart": "4.14.0-canary.10",
|
|
17
|
+
"@graphcommerce/magento-cart-payment-method": "4.14.0-canary.10",
|
|
18
|
+
"@graphcommerce/magento-cart-shipping-method": "4.14.0-canary.10",
|
|
19
|
+
"@graphcommerce/magento-product": "4.14.0-canary.10",
|
|
20
|
+
"@graphcommerce/next-ui": "4.31.0-canary.6",
|
|
21
|
+
"@graphcommerce/next-config": "4.31.0-canary.6"
|
|
18
22
|
},
|
|
19
23
|
"devDependencies": {
|
|
20
24
|
"@graphcommerce/eslint-config-pwa": "^4.1.11",
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { AddProductsToCartFormProps } from '@graphcommerce/magento-product'
|
|
2
|
+
import { PluginProps } from '@graphcommerce/next-config'
|
|
3
|
+
import { gtagAddToCart } from '../events/gtagAddToCart/gtagAddToCart'
|
|
4
|
+
|
|
5
|
+
export const component = 'AddProductsToCartForm'
|
|
6
|
+
export const exported = '@graphcommerce/magento-product'
|
|
7
|
+
|
|
8
|
+
/** When a product is added to the Cart, send a Google Analytics event */
|
|
9
|
+
function GaAddProductsToCartForm(props: PluginProps<AddProductsToCartFormProps>) {
|
|
10
|
+
const { Prev, onComplete, ...rest } = props
|
|
11
|
+
|
|
12
|
+
return (
|
|
13
|
+
<Prev
|
|
14
|
+
{...rest}
|
|
15
|
+
onComplete={async (data, variables) => {
|
|
16
|
+
await Promise.all([gtagAddToCart(data, variables), onComplete?.(data, variables)])
|
|
17
|
+
}}
|
|
18
|
+
/>
|
|
19
|
+
)
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export const Plugin = GaAddProductsToCartForm
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { CartStartCheckoutProps } from '@graphcommerce/magento-cart'
|
|
2
|
+
import { PluginProps } from '@graphcommerce/next-config'
|
|
3
|
+
import { gtagBeginCheckout } from '../events/gtagBeginCheckout/gtagBeginCheckout'
|
|
4
|
+
|
|
5
|
+
export const component = 'CartStartCheckout'
|
|
6
|
+
export const exported = '@graphcommerce/magento-cart'
|
|
7
|
+
|
|
8
|
+
export function GaCartStartCheckout(props: PluginProps<CartStartCheckoutProps>) {
|
|
9
|
+
const { Prev, onStart, ...rest } = props
|
|
10
|
+
return (
|
|
11
|
+
<Prev
|
|
12
|
+
{...rest}
|
|
13
|
+
onStart={(e, cart) => {
|
|
14
|
+
gtagBeginCheckout(cart)
|
|
15
|
+
onStart?.(e, cart)
|
|
16
|
+
}}
|
|
17
|
+
/>
|
|
18
|
+
)
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export const Plugin = GaCartStartCheckout
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { CartStartCheckoutLinkOrButtonProps } from '@graphcommerce/magento-cart'
|
|
2
|
+
import { PluginProps } from '@graphcommerce/next-config'
|
|
3
|
+
import { gtagBeginCheckout } from '../events/gtagBeginCheckout/gtagBeginCheckout'
|
|
4
|
+
|
|
5
|
+
export const component = 'CartStartCheckoutLinkOrButton'
|
|
6
|
+
export const exported = '@graphcommerce/magento-cart'
|
|
7
|
+
|
|
8
|
+
export function GaCartStartCheckoutLinkOrButton(
|
|
9
|
+
props: PluginProps<CartStartCheckoutLinkOrButtonProps>,
|
|
10
|
+
) {
|
|
11
|
+
const { Prev, onStart, ...rest } = props
|
|
12
|
+
return (
|
|
13
|
+
<Prev
|
|
14
|
+
{...rest}
|
|
15
|
+
onStart={(e, cart) => {
|
|
16
|
+
gtagBeginCheckout(cart)
|
|
17
|
+
onStart?.(e, cart)
|
|
18
|
+
}}
|
|
19
|
+
/>
|
|
20
|
+
)
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export const Plugin = GaCartStartCheckoutLinkOrButton
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { PagesProps } from '@graphcommerce/framer-next-pages'
|
|
2
|
+
import type { PluginProps } from '@graphcommerce/next-config'
|
|
3
|
+
import { GoogleAnalyticsScript } from '../components/GoogleAnalyticsScript'
|
|
4
|
+
|
|
5
|
+
export const component = 'FramerNextPages'
|
|
6
|
+
export const exported = '@graphcommerce/framer-next-pages'
|
|
7
|
+
|
|
8
|
+
let warned = false
|
|
9
|
+
|
|
10
|
+
function GaFramerNextPages(props: PluginProps<PagesProps>) {
|
|
11
|
+
const { Prev, ...rest } = props
|
|
12
|
+
|
|
13
|
+
if (process.env.NEXT_PUBLIC_GOOGLE_ANALYTICS) {
|
|
14
|
+
return (
|
|
15
|
+
<>
|
|
16
|
+
<GoogleAnalyticsScript />
|
|
17
|
+
<Prev {...rest} />
|
|
18
|
+
</>
|
|
19
|
+
)
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
23
|
+
if (!warned) {
|
|
24
|
+
console.info(
|
|
25
|
+
'[@graphcommerce/googleanalytics]: process.env.NEXT_PUBLIC_GOOGLE_ANALYTICS not found',
|
|
26
|
+
)
|
|
27
|
+
warned = true
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return <Prev {...rest} />
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export const Plugin = GaFramerNextPages
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { useCartQuery } from '@graphcommerce/magento-cart'
|
|
2
|
+
import { PaymentMethodButtonProps } from '@graphcommerce/magento-cart-payment-method'
|
|
3
|
+
import { GetPaymentMethodContextDocument } from '@graphcommerce/magento-cart-payment-method/PaymentMethodContext/GetPaymentMethodContext.gql'
|
|
4
|
+
import { PluginProps } from '@graphcommerce/next-config'
|
|
5
|
+
import { gtagAddPaymentInfo } from '../events/gtagAddPaymentInfo/gtagAddPaymentInfo'
|
|
6
|
+
|
|
7
|
+
export const component = 'PaymentMethodButton'
|
|
8
|
+
export const exported = '@graphcommerce/magento-cart-payment-method'
|
|
9
|
+
|
|
10
|
+
function GaPaymentMethodButton(props: PluginProps<PaymentMethodButtonProps>) {
|
|
11
|
+
const { Prev, onSubmitSuccessful, ...rest } = props
|
|
12
|
+
const methodContext = useCartQuery(GetPaymentMethodContextDocument)
|
|
13
|
+
|
|
14
|
+
return (
|
|
15
|
+
<Prev
|
|
16
|
+
{...rest}
|
|
17
|
+
onSubmitSuccessful={() => {
|
|
18
|
+
gtagAddPaymentInfo(methodContext.data?.cart)
|
|
19
|
+
onSubmitSuccessful?.()
|
|
20
|
+
}}
|
|
21
|
+
/>
|
|
22
|
+
)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export const Plugin = GaPaymentMethodButton
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { PaymentMethodContextProviderProps } from '@graphcommerce/magento-cart-payment-method'
|
|
2
|
+
import type { PluginProps } from '@graphcommerce/next-config'
|
|
3
|
+
|
|
4
|
+
export const component = 'PaymentMethodContextProvider'
|
|
5
|
+
export const exported = '@graphcommerce/magento-cart-payment-method'
|
|
6
|
+
|
|
7
|
+
function GaPaymentMethodContextProvider(props: PluginProps<PaymentMethodContextProviderProps>) {
|
|
8
|
+
const { Prev, onSuccess, ...rest } = props
|
|
9
|
+
return (
|
|
10
|
+
<Prev
|
|
11
|
+
{...rest}
|
|
12
|
+
onSuccess={async (orderNumber, cart) => {
|
|
13
|
+
// Todo - add GA event here
|
|
14
|
+
await onSuccess?.(orderNumber, cart)
|
|
15
|
+
}}
|
|
16
|
+
/>
|
|
17
|
+
)
|
|
18
|
+
}
|
|
19
|
+
export const Plugin = GaPaymentMethodContextProvider
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { ProductItemsGridProps } from '@graphcommerce/magento-product'
|
|
2
|
+
import { PluginProps } from '@graphcommerce/next-config'
|
|
3
|
+
import { gtagSelectItem } from '../events/gtagSelectItem/gtagSelectItem'
|
|
4
|
+
import { useGtagViewItemList } from '../events/useGtagViewItemList/useGtagViewItemList'
|
|
5
|
+
|
|
6
|
+
export const component = 'ProductListItemsBase'
|
|
7
|
+
export const exported = '@graphcommerce/magento-product'
|
|
8
|
+
|
|
9
|
+
export function GaProductListItemsBase(props: PluginProps<ProductItemsGridProps>) {
|
|
10
|
+
const { Prev, onClick, ...rest } = props
|
|
11
|
+
|
|
12
|
+
useGtagViewItemList(props)
|
|
13
|
+
|
|
14
|
+
return (
|
|
15
|
+
<Prev
|
|
16
|
+
{...rest}
|
|
17
|
+
onClick={(e, item) => {
|
|
18
|
+
gtagSelectItem({ item })
|
|
19
|
+
onClick?.(e, item)
|
|
20
|
+
}}
|
|
21
|
+
/>
|
|
22
|
+
)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export const Plugin = GaProductListItemsBase
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { ShippingMethodFormProps } from '@graphcommerce/magento-cart-shipping-method'
|
|
2
|
+
import { PluginProps } from '@graphcommerce/next-config'
|
|
3
|
+
import { gtagAddShippingInfo } from '../events/gtagAddShippingInfo/gtagAddShippingInfo'
|
|
4
|
+
|
|
5
|
+
export const component = 'ShippingMethodForm'
|
|
6
|
+
export const exported = '@graphcommerce/magento-cart-shipping-method'
|
|
7
|
+
|
|
8
|
+
/** When the ShippingMethod is submitted the result is sent to Google Analytics */
|
|
9
|
+
export function GaShippingMethodForm(props: PluginProps<ShippingMethodFormProps>) {
|
|
10
|
+
const { Prev, onComplete, ...rest } = props
|
|
11
|
+
return (
|
|
12
|
+
<Prev
|
|
13
|
+
{...rest}
|
|
14
|
+
onComplete={(result) => {
|
|
15
|
+
const cart = result.data?.setShippingMethodsOnCart?.cart
|
|
16
|
+
if (!cart) return
|
|
17
|
+
gtagAddShippingInfo(cart)
|
|
18
|
+
}}
|
|
19
|
+
/>
|
|
20
|
+
)
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export const Plugin = GaShippingMethodForm
|