@graphcommerce/googleanalytics 6.0.0-canary.36 → 6.0.0-canary.38
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 +8 -0
- package/components/GoogleAnalyticsScript.tsx +2 -13
- package/events/gtagAddPaymentInfo/gtagAddPaymentInfo.ts +18 -20
- package/events/gtagAddPurchaseInfo/gtagAddPurchaseInfo.ts +20 -22
- package/events/gtagAddToCart/gtagAddToCart.ts +23 -26
- package/events/gtagBeginCheckout/gtagBeginCheckout.ts +17 -20
- package/package.json +11 -11
- package/plugins/GaFramerNextPages.tsx +6 -21
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
+
## 6.0.0-canary.38
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#1835](https://github.com/graphcommerce-org/graphcommerce/pull/1835) [`393d62cf1`](https://github.com/graphcommerce-org/graphcommerce/commit/393d62cf1833a61eb98777b7eab91ea891668e57) - Analytics do not rely on env variable but use googleAnalyticsId config ([@paales](https://github.com/paales))
|
|
8
|
+
|
|
9
|
+
## 6.0.0-canary.37
|
|
10
|
+
|
|
3
11
|
## 6.0.0-canary.36
|
|
4
12
|
|
|
5
13
|
## 6.0.0-canary.35
|
|
@@ -1,19 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { useI18nConfig } from '@graphcommerce/next-ui'
|
|
2
2
|
import Script from 'next/script'
|
|
3
3
|
|
|
4
4
|
export function GoogleAnalyticsScript() {
|
|
5
|
-
const
|
|
6
|
-
const { locale } = useRouter()
|
|
7
|
-
let id = ''
|
|
8
|
-
|
|
9
|
-
if (!gaEnv) return null
|
|
10
|
-
|
|
11
|
-
if (gaEnv.startsWith('{') && locale) {
|
|
12
|
-
const GAConfig = JSON.parse(gaEnv)
|
|
13
|
-
id = GAConfig[locale]
|
|
14
|
-
} else {
|
|
15
|
-
id = gaEnv
|
|
16
|
-
}
|
|
5
|
+
const id = useI18nConfig().googleAnalyticsId ?? import.meta.graphCommerce.googleAnalyticsId
|
|
17
6
|
|
|
18
7
|
return (
|
|
19
8
|
<>
|
|
@@ -1,24 +1,22 @@
|
|
|
1
1
|
import { GtagAddPaymentInfoFragment } from './GtagAddPaymentInfo.gql'
|
|
2
2
|
|
|
3
3
|
export function gtagAddPaymentInfo<C extends GtagAddPaymentInfoFragment>(cart?: C | null) {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
})
|
|
23
|
-
}
|
|
4
|
+
globalThis.gtag?.('event', 'add_payment_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
|
+
payment_type: cart?.selected_payment_method?.code,
|
|
9
|
+
items: cart?.items?.map((item) => ({
|
|
10
|
+
item_id: item?.product.sku,
|
|
11
|
+
item_name: item?.product.name,
|
|
12
|
+
currency: item?.prices?.price.currency,
|
|
13
|
+
discount: item?.prices?.discounts?.reduce(
|
|
14
|
+
// eslint-disable-next-line @typescript-eslint/restrict-plus-operands
|
|
15
|
+
(sum, discount) => sum + (discount?.amount?.value ?? 0),
|
|
16
|
+
0,
|
|
17
|
+
),
|
|
18
|
+
price: item?.prices?.price.value,
|
|
19
|
+
quantity: item?.quantity,
|
|
20
|
+
})),
|
|
21
|
+
})
|
|
24
22
|
}
|
|
@@ -4,26 +4,24 @@ export function gtagAddPurchaseInfo(
|
|
|
4
4
|
orderNumber: string,
|
|
5
5
|
cart: PaymentMethodContextFragment | null | undefined,
|
|
6
6
|
) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
})
|
|
28
|
-
}
|
|
7
|
+
globalThis.gtag?.('event', 'purchase', {
|
|
8
|
+
transaction_id: orderNumber,
|
|
9
|
+
currency: cart?.prices?.grand_total?.currency,
|
|
10
|
+
value: cart?.prices?.grand_total?.value,
|
|
11
|
+
coupon: cart?.applied_coupons?.map((coupon) => coupon?.code),
|
|
12
|
+
payment_type: cart?.selected_payment_method?.code,
|
|
13
|
+
tax: cart?.prices?.applied_taxes?.reduce((sum, tax) => sum + (tax?.amount?.value ?? 0), 0),
|
|
14
|
+
items: cart?.items?.map((item) => ({
|
|
15
|
+
item_id: item?.product.sku,
|
|
16
|
+
item_name: item?.product.name,
|
|
17
|
+
currency: item?.prices?.price.currency,
|
|
18
|
+
discount: item?.prices?.discounts?.reduce(
|
|
19
|
+
// eslint-disable-next-line @typescript-eslint/restrict-plus-operands
|
|
20
|
+
(sum, discount) => sum + (discount?.amount?.value ?? 0),
|
|
21
|
+
0,
|
|
22
|
+
),
|
|
23
|
+
price: item?.prices?.price.value,
|
|
24
|
+
quantity: item?.quantity,
|
|
25
|
+
})),
|
|
26
|
+
})
|
|
29
27
|
}
|
|
@@ -8,33 +8,30 @@ export const gtagAddToCart = (
|
|
|
8
8
|
result: FetchResult<AddProductsToCartMutation>,
|
|
9
9
|
variables: AddProductsToCartMutationVariables,
|
|
10
10
|
) => {
|
|
11
|
-
|
|
12
|
-
const addedItem = result.data?.addProductsToCart?.cart.items?.slice(-1)[0]
|
|
11
|
+
const addedItem = result.data?.addProductsToCart?.cart.items?.slice(-1)[0]
|
|
13
12
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
const addToCartValue = pricePerItemInclTax * variables.cartItems[0].quantity
|
|
13
|
+
if (addedItem && addedItem.prices && addedItem.prices.row_total_including_tax.value) {
|
|
14
|
+
// we need to manually calculate pricePerItemInclTax (https://github.com/magento/magento2/issues/33848)
|
|
15
|
+
const pricePerItemInclTax = addedItem.prices.row_total_including_tax.value / addedItem.quantity
|
|
16
|
+
const addToCartValue = pricePerItemInclTax * variables.cartItems[0].quantity
|
|
19
17
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
}
|
|
18
|
+
globalThis.gtag?.('event', 'add_to_cart', {
|
|
19
|
+
currency: addedItem?.prices?.price.currency,
|
|
20
|
+
value: addToCartValue,
|
|
21
|
+
items: [
|
|
22
|
+
{
|
|
23
|
+
item_id: addedItem?.product.sku,
|
|
24
|
+
item_name: addedItem?.product.name,
|
|
25
|
+
currency: addedItem?.prices?.price.currency,
|
|
26
|
+
price: pricePerItemInclTax,
|
|
27
|
+
quantity: variables.cartItems[0].quantity,
|
|
28
|
+
discount: addedItem?.prices?.discounts?.reduce(
|
|
29
|
+
// eslint-disable-next-line @typescript-eslint/restrict-plus-operands
|
|
30
|
+
(sum, discount) => sum + (discount?.amount?.value ?? 0),
|
|
31
|
+
0,
|
|
32
|
+
),
|
|
33
|
+
},
|
|
34
|
+
],
|
|
35
|
+
})
|
|
39
36
|
}
|
|
40
37
|
}
|
|
@@ -1,24 +1,21 @@
|
|
|
1
1
|
import { GtagBeginCheckoutFragment } from './GtagBeginCheckout.gql'
|
|
2
2
|
|
|
3
3
|
export function gtagBeginCheckout<C extends GtagBeginCheckoutFragment>(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', 'begin_checkout', {
|
|
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
|
}
|
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": "6.0.0-canary.
|
|
5
|
+
"version": "6.0.0-canary.38",
|
|
6
6
|
"sideEffects": false,
|
|
7
7
|
"prettier": "@graphcommerce/prettier-config-pwa",
|
|
8
8
|
"eslintConfig": {
|
|
@@ -12,18 +12,18 @@
|
|
|
12
12
|
}
|
|
13
13
|
},
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@graphcommerce/graphql-mesh": "6.0.0-canary.
|
|
16
|
-
"@graphcommerce/magento-cart": "6.0.0-canary.
|
|
17
|
-
"@graphcommerce/magento-cart-payment-method": "6.0.0-canary.
|
|
18
|
-
"@graphcommerce/magento-cart-shipping-method": "6.0.0-canary.
|
|
19
|
-
"@graphcommerce/magento-product": "6.0.0-canary.
|
|
20
|
-
"@graphcommerce/next-config": "6.0.0-canary.
|
|
21
|
-
"@graphcommerce/next-ui": "6.0.0-canary.
|
|
15
|
+
"@graphcommerce/graphql-mesh": "6.0.0-canary.38",
|
|
16
|
+
"@graphcommerce/magento-cart": "6.0.0-canary.38",
|
|
17
|
+
"@graphcommerce/magento-cart-payment-method": "6.0.0-canary.38",
|
|
18
|
+
"@graphcommerce/magento-cart-shipping-method": "6.0.0-canary.38",
|
|
19
|
+
"@graphcommerce/magento-product": "6.0.0-canary.38",
|
|
20
|
+
"@graphcommerce/next-config": "6.0.0-canary.38",
|
|
21
|
+
"@graphcommerce/next-ui": "6.0.0-canary.38"
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {
|
|
24
|
-
"@graphcommerce/eslint-config-pwa": "6.0.0-canary.
|
|
25
|
-
"@graphcommerce/prettier-config-pwa": "6.0.0-canary.
|
|
26
|
-
"@graphcommerce/typescript-config-pwa": "6.0.0-canary.
|
|
24
|
+
"@graphcommerce/eslint-config-pwa": "6.0.0-canary.38",
|
|
25
|
+
"@graphcommerce/prettier-config-pwa": "6.0.0-canary.38",
|
|
26
|
+
"@graphcommerce/typescript-config-pwa": "6.0.0-canary.38",
|
|
27
27
|
"@types/gtag.js": "^0.0.12"
|
|
28
28
|
},
|
|
29
29
|
"peerDependencies": {
|
|
@@ -6,30 +6,15 @@ export const component = 'FramerNextPages'
|
|
|
6
6
|
export const exported = '@graphcommerce/framer-next-pages'
|
|
7
7
|
export const ifConfig: IfConfig = 'googleAnalyticsId'
|
|
8
8
|
|
|
9
|
-
let warned = false
|
|
10
|
-
|
|
11
9
|
function GaFramerNextPages(props: PluginProps<PagesProps>) {
|
|
12
10
|
const { Prev, ...rest } = props
|
|
13
11
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
)
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
24
|
-
if (!warned) {
|
|
25
|
-
console.info(
|
|
26
|
-
'[@graphcommerce/googleanalytics]: process.env.NEXT_PUBLIC_GOOGLE_ANALYTICS not found',
|
|
27
|
-
)
|
|
28
|
-
warned = true
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
return <Prev {...rest} />
|
|
12
|
+
return (
|
|
13
|
+
<>
|
|
14
|
+
<GoogleAnalyticsScript />
|
|
15
|
+
<Prev {...rest} />
|
|
16
|
+
</>
|
|
17
|
+
)
|
|
33
18
|
}
|
|
34
19
|
|
|
35
20
|
export const Plugin = GaFramerNextPages
|