@graphcommerce/googleanalytics 3.0.0 → 3.0.2
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 +14 -0
- package/events/{GtagAddPaymentInfo.graphql → gtagAddPaymentInfo/GtagAddPaymentInfo.graphql} +0 -0
- package/events/{gtagAddPaymentInfo.ts → gtagAddPaymentInfo/gtagAddPaymentInfo.ts} +2 -2
- package/events/{GtagAddShippingInfo.graphql → gtagAddShippingInfo/GtagAddShippingInfo.graphql} +0 -0
- package/events/{gtagAddShippingInfo.ts → gtagAddShippingInfo/gtagAddShippingInfo.ts} +2 -2
- package/events/{GtagAddToCart.graphql → gtagAddToCart/GtagAddToCart.graphql} +0 -0
- package/events/{gtagAddToCart.ts → gtagAddToCart/gtagAddToCart.ts} +0 -0
- package/events/{GtagBeginCheckout.graphql → gtagBeginCheckout/GtagBeginCheckout.graphql} +0 -0
- package/events/{gtagBeginCheckout.ts → gtagBeginCheckout/gtagBeginCheckout.ts} +2 -2
- package/events/gtagSelectItem/gtagSelectItem.ts +17 -0
- package/events/productToGtagItem/ProductToGtagItem.graphql +20 -0
- package/events/productToGtagItem/productToGtagItem.ts +38 -0
- package/events/{useGtagPurchase.ts → useGtagPurchase/useGtagPurchase.ts} +1 -1
- package/events/useGtagViewItemList/useGtagViewItemList.ts +36 -0
- package/index.ts +7 -7
- package/package.json +3 -3
- package/events/gtagSelectItem.ts +0 -20
- package/events/useGtagViewItemList.ts +0 -24
- package/types/types.ts +0 -31
- package/utils/index.ts +0 -19
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# Change Log
|
|
2
2
|
|
|
3
|
+
## 3.0.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [[`2b5451395`](https://github.com/graphcommerce-org/graphcommerce/commit/2b5451395dc1173de55d18d08968866e561f90ab), [`e76df6dc3`](https://github.com/graphcommerce-org/graphcommerce/commit/e76df6dc37c11c793a5d008ba36932d17dc23855), [`c4ed376e2`](https://github.com/graphcommerce-org/graphcommerce/commit/c4ed376e2c72b16b34704d7d1ca69c074de172ba), [`78d7d51cb`](https://github.com/graphcommerce-org/graphcommerce/commit/78d7d51cb1551601d3a4756cd1f2157a49ff93b9), [`0bd9ea582`](https://github.com/graphcommerce-org/graphcommerce/commit/0bd9ea58230dde79c5fe2cdb07e9860151460270)]:
|
|
8
|
+
- @graphcommerce/magento-product@4.8.0
|
|
9
|
+
- @graphcommerce/next-ui@4.29.0
|
|
10
|
+
|
|
11
|
+
## 3.0.1
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- [#1676](https://github.com/graphcommerce-org/graphcommerce/pull/1676) [`55cabbbc5`](https://github.com/graphcommerce-org/graphcommerce/commit/55cabbbc517b35c5f909bd771e619a87614e4c97) Thanks [@paales](https://github.com/paales)! - Fix issue where gtag wouldn't exist
|
|
16
|
+
|
|
3
17
|
## 3.0.0
|
|
4
18
|
|
|
5
19
|
### Major Changes
|
|
File without changes
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { GtagAddPaymentInfoFragment } from './GtagAddPaymentInfo.gql'
|
|
2
2
|
|
|
3
|
-
export function gtagAddPaymentInfo(cart?:
|
|
3
|
+
export function gtagAddPaymentInfo<C extends GtagAddPaymentInfoFragment>(cart?: C | null) {
|
|
4
4
|
if (process.env.NEXT_PUBLIC_GOOGLE_ANALYTICS) {
|
|
5
|
-
|
|
5
|
+
globalThis.gtag?.('event', 'add_payment_info', {
|
|
6
6
|
currency: cart?.prices?.grand_total?.currency,
|
|
7
7
|
value: cart?.prices?.grand_total?.value,
|
|
8
8
|
coupon: cart?.applied_coupons?.map((coupon) => coupon?.code),
|
package/events/{GtagAddShippingInfo.graphql → gtagAddShippingInfo/GtagAddShippingInfo.graphql}
RENAMED
|
File without changes
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { GtagAddShippingInfoFragment } from './GtagAddShippingInfo.gql'
|
|
2
2
|
|
|
3
|
-
export
|
|
3
|
+
export function gtagAddShippingInfo<C extends GtagAddShippingInfoFragment>(cart?: C | null) {
|
|
4
4
|
if (process.env.NEXT_PUBLIC_GOOGLE_ANALYTICS) {
|
|
5
|
-
|
|
5
|
+
globalThis.gtag?.('event', 'add_shipping_info', {
|
|
6
6
|
currency: cart?.prices?.grand_total?.currency,
|
|
7
7
|
value: cart?.prices?.grand_total?.value,
|
|
8
8
|
coupon: cart?.applied_coupons?.map((coupon) => coupon?.code),
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { GtagBeginCheckoutFragment } from './GtagBeginCheckout.gql'
|
|
2
2
|
|
|
3
|
-
export function gtagBeginCheckout(cart?:
|
|
3
|
+
export function gtagBeginCheckout<C extends GtagBeginCheckoutFragment>(cart?: C | null) {
|
|
4
4
|
if (process.env.NEXT_PUBLIC_GOOGLE_ANALYTICS) {
|
|
5
|
-
|
|
5
|
+
globalThis.gtag?.('event', 'begin_checkout', {
|
|
6
6
|
currency: cart?.prices?.grand_total?.currency,
|
|
7
7
|
value: cart?.prices?.grand_total?.value,
|
|
8
8
|
coupon: cart?.applied_coupons?.map((coupon) => coupon?.code),
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { ProductToGtagItemFragment } from '../productToGtagItem/ProductToGtagItem.gql'
|
|
2
|
+
import { productToGtagItem } from '../productToGtagItem/productToGtagItem'
|
|
3
|
+
|
|
4
|
+
type GtagSelectItemProps<T extends ProductToGtagItemFragment> = {
|
|
5
|
+
item: T
|
|
6
|
+
listId?: string
|
|
7
|
+
title?: string
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function gtagSelectItem<T extends ProductToGtagItemFragment>(props: GtagSelectItemProps<T>) {
|
|
11
|
+
const { item, listId: item_list_id, title: item_list_name } = props
|
|
12
|
+
globalThis.gtag?.('event', 'select_item', {
|
|
13
|
+
item_list_id,
|
|
14
|
+
item_list_name,
|
|
15
|
+
items: productToGtagItem(item),
|
|
16
|
+
})
|
|
17
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { ProductToGtagItemFragment } from './ProductToGtagItem.gql'
|
|
2
|
+
|
|
3
|
+
export type GtagItem = {
|
|
4
|
+
item_id: string
|
|
5
|
+
item_name: string
|
|
6
|
+
affiliation?: string
|
|
7
|
+
coupon?: string
|
|
8
|
+
currency?: string
|
|
9
|
+
discount?: number
|
|
10
|
+
index?: number
|
|
11
|
+
item_brand?: string
|
|
12
|
+
item_category?: string
|
|
13
|
+
item_category2?: string
|
|
14
|
+
item_category3?: string
|
|
15
|
+
item_category4?: string
|
|
16
|
+
item_category5?: string
|
|
17
|
+
item_list_id?: string
|
|
18
|
+
item_list_name?: string
|
|
19
|
+
item_variant?: string
|
|
20
|
+
location_id?: string
|
|
21
|
+
price?: number
|
|
22
|
+
quantity?: number
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export function productToGtagItem<P extends ProductToGtagItemFragment>(item: P): GtagItem {
|
|
26
|
+
return {
|
|
27
|
+
item_name: item.name ?? '',
|
|
28
|
+
item_id: item.sku ?? '',
|
|
29
|
+
price: item.price_range?.minimum_price.final_price.value ?? undefined,
|
|
30
|
+
currency: item.price_range?.minimum_price.final_price.currency ?? undefined,
|
|
31
|
+
discount: item.price_range?.minimum_price.discount?.amount_off ?? undefined,
|
|
32
|
+
item_category: item.categories?.[0]?.name ?? undefined,
|
|
33
|
+
item_category2: item.categories?.[1]?.name ?? undefined,
|
|
34
|
+
item_category3: item.categories?.[2]?.name ?? undefined,
|
|
35
|
+
item_category4: item.categories?.[3]?.name ?? undefined,
|
|
36
|
+
item_category5: item.categories?.[4]?.name ?? undefined,
|
|
37
|
+
}
|
|
38
|
+
}
|
|
@@ -3,7 +3,7 @@ export const useGtagPurchase = () => {
|
|
|
3
3
|
|
|
4
4
|
if (process.env.NEXT_PUBLIC_GOOGLE_ANALYTICS) {
|
|
5
5
|
// console.log(cart, 'trigger gtagPurchase')
|
|
6
|
-
//
|
|
6
|
+
// globalThis.gtag?.('event', 'purchase', {
|
|
7
7
|
// currency: cart?.prices?.grand_total?.currency,
|
|
8
8
|
// // transaction_id:,
|
|
9
9
|
// // shipping:,
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { nonNullable, useMemoDeep } from '@graphcommerce/next-ui'
|
|
2
|
+
import { useEffect } from 'react'
|
|
3
|
+
import { ProductToGtagItemFragment } from '../productToGtagItem/ProductToGtagItem.gql'
|
|
4
|
+
import { GtagItem, productToGtagItem } from '../productToGtagItem/productToGtagItem'
|
|
5
|
+
|
|
6
|
+
export type UseGtagViewItemListProps<
|
|
7
|
+
P extends ProductToGtagItemFragment = ProductToGtagItemFragment,
|
|
8
|
+
> = {
|
|
9
|
+
title: string
|
|
10
|
+
items?: (P | null | undefined)[] | null
|
|
11
|
+
listId?: string
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export type ViewItemList = {
|
|
15
|
+
item_list_id: string
|
|
16
|
+
item_list_name: string
|
|
17
|
+
items: GtagItem[]
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function useGtagViewItemList<P extends ProductToGtagItemFragment>(
|
|
21
|
+
props: UseGtagViewItemListProps<P>,
|
|
22
|
+
) {
|
|
23
|
+
const { title, items, listId } = props
|
|
24
|
+
|
|
25
|
+
const eventData: ViewItemList = useMemoDeep(
|
|
26
|
+
() => ({
|
|
27
|
+
item_list_id: listId ?? title?.toLowerCase().replace(/\s/g, '_'),
|
|
28
|
+
item_list_name: title,
|
|
29
|
+
items:
|
|
30
|
+
items?.map((item) => (item ? productToGtagItem(item) : null)).filter(nonNullable) ?? [],
|
|
31
|
+
}),
|
|
32
|
+
[listId, items, title],
|
|
33
|
+
)
|
|
34
|
+
|
|
35
|
+
useEffect(() => globalThis.gtag?.('event', 'view_item_list', eventData), [eventData])
|
|
36
|
+
}
|
package/index.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
export * from './components'
|
|
2
|
-
export * from './events/useGtagViewItemList'
|
|
3
|
-
export * from './events/gtagBeginCheckout'
|
|
4
|
-
export * from './events/gtagAddPaymentInfo'
|
|
5
|
-
export * from './events/gtagAddShippingInfo'
|
|
6
|
-
export * from './events/gtagSelectItem'
|
|
7
|
-
export * from './events/useGtagPurchase'
|
|
8
|
-
export * from './events/gtagAddToCart'
|
|
2
|
+
export * from './events/useGtagViewItemList/useGtagViewItemList'
|
|
3
|
+
export * from './events/gtagBeginCheckout/gtagBeginCheckout'
|
|
4
|
+
export * from './events/gtagAddPaymentInfo/gtagAddPaymentInfo'
|
|
5
|
+
export * from './events/gtagAddShippingInfo/gtagAddShippingInfo'
|
|
6
|
+
export * from './events/gtagSelectItem/gtagSelectItem'
|
|
7
|
+
export * from './events/useGtagPurchase/useGtagPurchase'
|
|
8
|
+
export * from './events/gtagAddToCart/gtagAddToCart'
|
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.0.2",
|
|
6
6
|
"sideEffects": false,
|
|
7
7
|
"prettier": "@graphcommerce/prettier-config-pwa",
|
|
8
8
|
"eslintConfig": {
|
|
@@ -13,8 +13,8 @@
|
|
|
13
13
|
},
|
|
14
14
|
"dependencies": {
|
|
15
15
|
"@graphcommerce/graphql-mesh": "4.2.0",
|
|
16
|
-
"@graphcommerce/magento-product": "4.
|
|
17
|
-
"@graphcommerce/next-ui": "4.
|
|
16
|
+
"@graphcommerce/magento-product": "4.8.0",
|
|
17
|
+
"@graphcommerce/next-ui": "4.29.0"
|
|
18
18
|
},
|
|
19
19
|
"devDependencies": {
|
|
20
20
|
"@graphcommerce/eslint-config-pwa": "^4.1.8",
|
package/events/gtagSelectItem.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { ProductInterface } from '@graphcommerce/graphql-mesh'
|
|
2
|
-
import { itemToEvent } from '../utils'
|
|
3
|
-
|
|
4
|
-
type GtagSelectItemProps = {
|
|
5
|
-
item: Partial<ProductInterface>
|
|
6
|
-
listId?: string
|
|
7
|
-
title?: string
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export function gtagSelectItem({ item, listId, title }: GtagSelectItemProps) {
|
|
11
|
-
gtag?.('event', 'select_item', {
|
|
12
|
-
item_list_id: listId,
|
|
13
|
-
item_list_name: title,
|
|
14
|
-
items: itemToEvent({
|
|
15
|
-
...item,
|
|
16
|
-
name: item.name ?? '',
|
|
17
|
-
sku: item.sku ?? '',
|
|
18
|
-
}),
|
|
19
|
-
})
|
|
20
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { ProductListItemFragment } from '@graphcommerce/magento-product'
|
|
2
|
-
import { filterNonNullableKeys } from '@graphcommerce/next-ui'
|
|
3
|
-
import { useEffect, useMemo } from 'react'
|
|
4
|
-
import { ViewItemList } from '../types/types'
|
|
5
|
-
import { itemToEvent } from '../utils'
|
|
6
|
-
|
|
7
|
-
export type UseGtagViewItemListProps = {
|
|
8
|
-
title: string
|
|
9
|
-
items?: (ProductListItemFragment | null | undefined)[] | null | undefined
|
|
10
|
-
listId?: string
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export function useGtagViewItemList({ title, items, listId }: UseGtagViewItemListProps) {
|
|
14
|
-
const eventData: ViewItemList = useMemo(
|
|
15
|
-
() => ({
|
|
16
|
-
item_list_id: listId ?? title?.toLowerCase().replace(/\s/g, '_'),
|
|
17
|
-
item_list_name: title,
|
|
18
|
-
items: filterNonNullableKeys(items, ['name', 'sku']).map((item) => itemToEvent(item)),
|
|
19
|
-
}),
|
|
20
|
-
[listId, items, title],
|
|
21
|
-
)
|
|
22
|
-
|
|
23
|
-
useEffect(() => gtag?.('event', 'view_item_list', eventData), [eventData])
|
|
24
|
-
}
|
package/types/types.ts
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import type { ProductInterface } from '@graphcommerce/graphql-mesh'
|
|
2
|
-
import { RequiredKeys } from '@graphcommerce/next-ui'
|
|
3
|
-
|
|
4
|
-
export type Item = {
|
|
5
|
-
item_id: string
|
|
6
|
-
item_name: string
|
|
7
|
-
affiliation?: string
|
|
8
|
-
coupon?: string
|
|
9
|
-
currency?: string
|
|
10
|
-
discount?: number
|
|
11
|
-
index?: number
|
|
12
|
-
item_brand?: string
|
|
13
|
-
item_category?: string
|
|
14
|
-
item_category2?: string
|
|
15
|
-
item_category3?: string
|
|
16
|
-
item_category4?: string
|
|
17
|
-
item_category5?: string
|
|
18
|
-
item_list_id?: string
|
|
19
|
-
item_list_name?: string
|
|
20
|
-
item_variant?: string
|
|
21
|
-
location_id?: string
|
|
22
|
-
price?: number
|
|
23
|
-
quantity?: number
|
|
24
|
-
}
|
|
25
|
-
export type ViewItemList = {
|
|
26
|
-
item_list_id: string
|
|
27
|
-
item_list_name: string
|
|
28
|
-
items: Item[]
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export type ProductItem = RequiredKeys<Partial<ProductInterface>, 'name' | 'sku'>
|
package/utils/index.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { filterNonNullableKeys } from '@graphcommerce/next-ui'
|
|
2
|
-
import { Item, ProductItem } from '../types/types'
|
|
3
|
-
|
|
4
|
-
export function itemToEvent(item: ProductItem): Item {
|
|
5
|
-
const categories = filterNonNullableKeys(item.categories, ['include_in_menu', 'name'])
|
|
6
|
-
|
|
7
|
-
return {
|
|
8
|
-
item_name: item.name,
|
|
9
|
-
item_id: item.sku,
|
|
10
|
-
price: item.price_range?.minimum_price.final_price.value ?? undefined,
|
|
11
|
-
currency: item.price_range?.minimum_price.final_price.currency ?? undefined,
|
|
12
|
-
discount: item.price_range?.minimum_price.discount?.amount_off ?? undefined,
|
|
13
|
-
item_category: categories[0]?.name,
|
|
14
|
-
item_category2: categories[1]?.name,
|
|
15
|
-
item_category3: categories[2]?.name,
|
|
16
|
-
item_category4: categories[3]?.name,
|
|
17
|
-
item_category5: categories[4]?.name,
|
|
18
|
-
}
|
|
19
|
-
}
|