@segment/analytics-browser-actions-google-analytics-4 1.0.0
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/package.json +20 -0
- package/src/__tests__/addPaymentInfo.test.ts +101 -0
- package/src/__tests__/addToCart.test.ts +95 -0
- package/src/__tests__/addToWishlist.test.ts +95 -0
- package/src/__tests__/beginCheckout.test.ts +101 -0
- package/src/__tests__/customEvent.test.ts +70 -0
- package/src/__tests__/generateLead.test.ts +68 -0
- package/src/__tests__/login.test.ts +63 -0
- package/src/__tests__/purchase.test.ts +103 -0
- package/src/__tests__/refund.test.ts +103 -0
- package/src/__tests__/removeFromCart.test.ts +99 -0
- package/src/__tests__/search.test.ts +64 -0
- package/src/__tests__/selectItem.test.ts +96 -0
- package/src/__tests__/selectPromotion.test.ts +111 -0
- package/src/__tests__/signUp.test.ts +62 -0
- package/src/__tests__/viewCart.test.ts +96 -0
- package/src/__tests__/viewItem.test.ts +96 -0
- package/src/__tests__/viewItemList.test.ts +96 -0
- package/src/__tests__/viewPromotion.test.ts +111 -0
- package/src/addPaymentInfo/generated-types.ts +117 -0
- package/src/addPaymentInfo/index.ts +48 -0
- package/src/addToCart/generated-types.ts +109 -0
- package/src/addToCart/index.ts +36 -0
- package/src/addToWishlist/generated-types.ts +109 -0
- package/src/addToWishlist/index.ts +38 -0
- package/src/beginCheckout/generated-types.ts +113 -0
- package/src/beginCheckout/index.ts +38 -0
- package/src/customEvent/generated-types.ts +28 -0
- package/src/customEvent/index.ts +52 -0
- package/src/ga4-functions.ts +8 -0
- package/src/ga4-properties.ts +368 -0
- package/src/ga4-types.ts +28 -0
- package/src/generateLead/generated-types.ts +28 -0
- package/src/generateLead/index.ts +32 -0
- package/src/generated-types.ts +56 -0
- package/src/index.ts +194 -0
- package/src/login/generated-types.ts +24 -0
- package/src/login/index.ts +31 -0
- package/src/purchase/generated-types.ts +125 -0
- package/src/purchase/index.ts +54 -0
- package/src/refund/generated-types.ts +129 -0
- package/src/refund/index.ts +57 -0
- package/src/removeFromCart/generated-types.ts +109 -0
- package/src/removeFromCart/index.ts +37 -0
- package/src/search/generated-types.ts +24 -0
- package/src/search/index.ts +30 -0
- package/src/selectItem/generated-types.ts +109 -0
- package/src/selectItem/index.ts +43 -0
- package/src/selectPromotion/generated-types.ts +137 -0
- package/src/selectPromotion/index.ts +67 -0
- package/src/setConfigurationFields/generated-types.ts +70 -0
- package/src/setConfigurationFields/index.ts +143 -0
- package/src/signUp/generated-types.ts +24 -0
- package/src/signUp/index.ts +29 -0
- package/src/types.ts +3 -0
- package/src/viewCart/generated-types.ts +109 -0
- package/src/viewCart/index.ts +36 -0
- package/src/viewItem/generated-types.ts +109 -0
- package/src/viewItem/index.ts +37 -0
- package/src/viewItemList/generated-types.ts +109 -0
- package/src/viewItemList/index.ts +36 -0
- package/src/viewPromotion/generated-types.ts +137 -0
- package/src/viewPromotion/index.ts +67 -0
- package/tsconfig.json +9 -0
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import type { BrowserActionDefinition } from '@segment/browser-destination-runtime/types'
|
|
2
|
+
import type { Settings } from '../generated-types'
|
|
3
|
+
import type { Payload } from './generated-types'
|
|
4
|
+
import { user_id, user_properties } from '../ga4-properties'
|
|
5
|
+
import { updateUser } from '../ga4-functions'
|
|
6
|
+
|
|
7
|
+
// Change from unknown to the partner SDK types
|
|
8
|
+
const action: BrowserActionDefinition<Settings, Function, Payload> = {
|
|
9
|
+
title: 'Set Configuration Fields',
|
|
10
|
+
description: 'Set custom values for the GA4 configuration fields.',
|
|
11
|
+
platform: 'web',
|
|
12
|
+
defaultSubscription: 'type = "identify" or type = "page"',
|
|
13
|
+
fields: {
|
|
14
|
+
user_id: user_id,
|
|
15
|
+
user_properties: user_properties,
|
|
16
|
+
ads_storage_consent_state: {
|
|
17
|
+
description:
|
|
18
|
+
'Consent state indicated by the user for ad cookies. Value must be “granted” or “denied.” This is only used if the Enable Consent Mode setting is on.',
|
|
19
|
+
label: 'Ads Storage Consent State',
|
|
20
|
+
type: 'string'
|
|
21
|
+
},
|
|
22
|
+
analytics_storage_consent_state: {
|
|
23
|
+
description:
|
|
24
|
+
'Consent state indicated by the user for ad cookies. Value must be “granted” or “denied.” This is only used if the Enable Consent Mode setting is on.',
|
|
25
|
+
label: 'Analytics Storage Consent State',
|
|
26
|
+
type: 'string'
|
|
27
|
+
},
|
|
28
|
+
campaign_content: {
|
|
29
|
+
description:
|
|
30
|
+
'Use campaign content to differentiate ads or links that point to the same URL. Setting this value will override the utm_content query parameter.',
|
|
31
|
+
label: 'Campaign Content',
|
|
32
|
+
type: 'string'
|
|
33
|
+
},
|
|
34
|
+
campaign_id: {
|
|
35
|
+
description:
|
|
36
|
+
'Use campaign ID to identify a specific campaign. Setting this value will override the utm_id query parameter. ',
|
|
37
|
+
label: 'Campaign ID',
|
|
38
|
+
type: 'string'
|
|
39
|
+
},
|
|
40
|
+
campaign_medium: {
|
|
41
|
+
description:
|
|
42
|
+
'Use campaign medium to identify a medium such as email or cost-per-click. Setting this value will override the utm_medium query parameter.',
|
|
43
|
+
label: 'Campaign Medium',
|
|
44
|
+
type: 'string'
|
|
45
|
+
},
|
|
46
|
+
campaign_name: {
|
|
47
|
+
description:
|
|
48
|
+
'Use campaign name to identify a specific product promotion or strategic campaign. Setting this value will override the utm_name query parameter.',
|
|
49
|
+
label: 'Campaign Name',
|
|
50
|
+
type: 'string'
|
|
51
|
+
},
|
|
52
|
+
campaign_source: {
|
|
53
|
+
description:
|
|
54
|
+
'Use campaign source to identify a search engine, newsletter name, or other source. Setting this value will override the utm_source query parameter.',
|
|
55
|
+
label: 'Campaign Source',
|
|
56
|
+
type: 'string'
|
|
57
|
+
},
|
|
58
|
+
campaign_term: {
|
|
59
|
+
description:
|
|
60
|
+
'Use campaign term to note the keywords for this ad. Setting this value will override the utm_term query parameter.',
|
|
61
|
+
label: 'Campaign Term',
|
|
62
|
+
type: 'string'
|
|
63
|
+
},
|
|
64
|
+
content_group: {
|
|
65
|
+
description: `Categorize pages and screens into custom buckets so you can see metrics for related groups of information. More information in [Google documentation](https://support.google.com/analytics/answer/11523339).`,
|
|
66
|
+
label: 'Content Group',
|
|
67
|
+
type: 'string'
|
|
68
|
+
},
|
|
69
|
+
language: {
|
|
70
|
+
description: `The language preference of the user. If not set, defaults to the user's navigator.language value.`,
|
|
71
|
+
label: 'Language',
|
|
72
|
+
type: 'string'
|
|
73
|
+
},
|
|
74
|
+
page_location: {
|
|
75
|
+
description: `The full URL of the page. If not set, defaults to the user's document.location value.`,
|
|
76
|
+
label: 'Page Location',
|
|
77
|
+
type: 'string'
|
|
78
|
+
},
|
|
79
|
+
page_referrer: {
|
|
80
|
+
description: `The referral source that brought traffic to a page. This value is also used to compute the traffic source. The format of this value is a URL. If not set, defaults to the user's document.referrer value.`,
|
|
81
|
+
label: 'Page Referrer',
|
|
82
|
+
type: 'string'
|
|
83
|
+
},
|
|
84
|
+
page_title: {
|
|
85
|
+
description: `The title of the page or document. If not set, defaults to the user's document.title value.`,
|
|
86
|
+
label: 'Page Title',
|
|
87
|
+
type: 'string'
|
|
88
|
+
},
|
|
89
|
+
screen_resolution: {
|
|
90
|
+
description: `The resolution of the screen. Format should be two positive integers separated by an x (i.e. 800x600). If not set, calculated from the user's window.screen value.`,
|
|
91
|
+
label: 'Screen Resolution',
|
|
92
|
+
type: 'string'
|
|
93
|
+
}
|
|
94
|
+
},
|
|
95
|
+
perform: (gtag, { payload, settings }) => {
|
|
96
|
+
updateUser(payload.user_id, payload.user_properties, gtag)
|
|
97
|
+
if (settings.enableConsentMode) {
|
|
98
|
+
window.gtag('consent', 'update', {
|
|
99
|
+
ad_storage: payload.ads_storage_consent_state,
|
|
100
|
+
analytics_storage: payload.analytics_storage_consent_state
|
|
101
|
+
})
|
|
102
|
+
}
|
|
103
|
+
if (payload.screen_resolution) {
|
|
104
|
+
gtag('set', { screen_resolution: payload.screen_resolution })
|
|
105
|
+
}
|
|
106
|
+
if (payload.page_title) {
|
|
107
|
+
gtag('set', { page_title: payload.page_title })
|
|
108
|
+
}
|
|
109
|
+
if (payload.page_referrer) {
|
|
110
|
+
gtag('set', { page_referrer: payload.page_referrer })
|
|
111
|
+
}
|
|
112
|
+
if (payload.page_location) {
|
|
113
|
+
gtag('set', { page_location: payload.page_location })
|
|
114
|
+
}
|
|
115
|
+
if (payload.language) {
|
|
116
|
+
gtag('set', { language: payload.language })
|
|
117
|
+
}
|
|
118
|
+
if (payload.content_group) {
|
|
119
|
+
gtag('set', { content_group: payload.content_group })
|
|
120
|
+
}
|
|
121
|
+
if (payload.campaign_term) {
|
|
122
|
+
gtag('set', { campaign_term: payload.campaign_term })
|
|
123
|
+
}
|
|
124
|
+
if (payload.campaign_source) {
|
|
125
|
+
gtag('set', { campaign_source: payload.campaign_source })
|
|
126
|
+
}
|
|
127
|
+
if (payload.campaign_name) {
|
|
128
|
+
gtag('set', { campaign_name: payload.campaign_name })
|
|
129
|
+
}
|
|
130
|
+
if (payload.campaign_medium) {
|
|
131
|
+
gtag('set', { campaign_medium: payload.campaign_medium })
|
|
132
|
+
}
|
|
133
|
+
if (payload.campaign_id) {
|
|
134
|
+
gtag('set', { campaign_id: payload.campaign_id })
|
|
135
|
+
}
|
|
136
|
+
if (payload.campaign_content) {
|
|
137
|
+
gtag('set', { campaign_content: payload.campaign_content })
|
|
138
|
+
}
|
|
139
|
+
gtag('event', 'page_view')
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
export default action
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// Generated file. DO NOT MODIFY IT BY HAND.
|
|
2
|
+
|
|
3
|
+
export interface Payload {
|
|
4
|
+
/**
|
|
5
|
+
* A unique identifier for a user. See Google's [User-ID for cross-platform analysis](https://support.google.com/analytics/answer/9213390) and [Reporting: deduplicate user counts](https://support.google.com/analytics/answer/9355949?hl=en) documentation for more information on this identifier.
|
|
6
|
+
*/
|
|
7
|
+
user_id?: string
|
|
8
|
+
/**
|
|
9
|
+
* The method used to login.
|
|
10
|
+
*/
|
|
11
|
+
method?: string
|
|
12
|
+
/**
|
|
13
|
+
* The user properties to send to Google Analytics 4. You must create user-scoped dimensions to ensure custom properties are picked up by Google. See Google’s [Custom user properties](https://support.google.com/analytics/answer/9269570) to learn how to set and register user properties.
|
|
14
|
+
*/
|
|
15
|
+
user_properties?: {
|
|
16
|
+
[k: string]: unknown
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* The event parameters to send to Google Analytics 4.
|
|
20
|
+
*/
|
|
21
|
+
params?: {
|
|
22
|
+
[k: string]: unknown
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { BrowserActionDefinition } from '@segment/browser-destination-runtime/types'
|
|
2
|
+
import type { Settings } from '../generated-types'
|
|
3
|
+
import type { Payload } from './generated-types'
|
|
4
|
+
|
|
5
|
+
import { user_properties, params, user_id, method } from '../ga4-properties'
|
|
6
|
+
import { updateUser } from '../ga4-functions'
|
|
7
|
+
|
|
8
|
+
const action: BrowserActionDefinition<Settings, Function, Payload> = {
|
|
9
|
+
title: 'Sign Up',
|
|
10
|
+
description: 'The method used for sign up.',
|
|
11
|
+
defaultSubscription: 'type = "track" and event = "Signed Up"',
|
|
12
|
+
platform: 'web',
|
|
13
|
+
fields: {
|
|
14
|
+
user_id: user_id,
|
|
15
|
+
method: method,
|
|
16
|
+
user_properties: user_properties,
|
|
17
|
+
params: params
|
|
18
|
+
},
|
|
19
|
+
perform: (gtag, { payload }) => {
|
|
20
|
+
updateUser(payload.user_id, payload.user_properties, gtag)
|
|
21
|
+
|
|
22
|
+
gtag('event', 'sign_up', {
|
|
23
|
+
method: payload.method,
|
|
24
|
+
...payload.params
|
|
25
|
+
})
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export default action
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
// Generated file. DO NOT MODIFY IT BY HAND.
|
|
2
|
+
|
|
3
|
+
export interface Payload {
|
|
4
|
+
/**
|
|
5
|
+
* A unique identifier for a user. See Google's [User-ID for cross-platform analysis](https://support.google.com/analytics/answer/9213390) and [Reporting: deduplicate user counts](https://support.google.com/analytics/answer/9355949?hl=en) documentation for more information on this identifier.
|
|
6
|
+
*/
|
|
7
|
+
user_id?: string
|
|
8
|
+
/**
|
|
9
|
+
* Currency of the items associated with the event, in 3-letter ISO 4217 format.
|
|
10
|
+
*/
|
|
11
|
+
currency?: string
|
|
12
|
+
/**
|
|
13
|
+
* The monetary value of the event.
|
|
14
|
+
*/
|
|
15
|
+
value?: number
|
|
16
|
+
/**
|
|
17
|
+
* The list of products purchased.
|
|
18
|
+
*/
|
|
19
|
+
items: {
|
|
20
|
+
/**
|
|
21
|
+
* Identifier for the product being purchased.
|
|
22
|
+
*/
|
|
23
|
+
item_id?: string
|
|
24
|
+
/**
|
|
25
|
+
* Name of the product being purchased.
|
|
26
|
+
*/
|
|
27
|
+
item_name?: string
|
|
28
|
+
/**
|
|
29
|
+
* A product affiliation to designate a supplying company or brick and mortar store location.
|
|
30
|
+
*/
|
|
31
|
+
affiliation?: string
|
|
32
|
+
/**
|
|
33
|
+
* Coupon code used for a purchase.
|
|
34
|
+
*/
|
|
35
|
+
coupon?: string
|
|
36
|
+
/**
|
|
37
|
+
* Currency of the purchase or items associated with the event, in 3-letter ISO 4217 format.
|
|
38
|
+
*/
|
|
39
|
+
currency?: string
|
|
40
|
+
/**
|
|
41
|
+
* Monetary value of discount associated with a purchase.
|
|
42
|
+
*/
|
|
43
|
+
discount?: number
|
|
44
|
+
/**
|
|
45
|
+
* The index/position of the item in a list.
|
|
46
|
+
*/
|
|
47
|
+
index?: number
|
|
48
|
+
/**
|
|
49
|
+
* Brand associated with the product.
|
|
50
|
+
*/
|
|
51
|
+
item_brand?: string
|
|
52
|
+
/**
|
|
53
|
+
* Product category.
|
|
54
|
+
*/
|
|
55
|
+
item_category?: string
|
|
56
|
+
/**
|
|
57
|
+
* Product category 2.
|
|
58
|
+
*/
|
|
59
|
+
item_category2?: string
|
|
60
|
+
/**
|
|
61
|
+
* Product category 3.
|
|
62
|
+
*/
|
|
63
|
+
item_category3?: string
|
|
64
|
+
/**
|
|
65
|
+
* Product category 4.
|
|
66
|
+
*/
|
|
67
|
+
item_category4?: string
|
|
68
|
+
/**
|
|
69
|
+
* Product category 5.
|
|
70
|
+
*/
|
|
71
|
+
item_category5?: string
|
|
72
|
+
/**
|
|
73
|
+
* The ID of the list in which the item was presented to the user.
|
|
74
|
+
*/
|
|
75
|
+
item_list_id?: string
|
|
76
|
+
/**
|
|
77
|
+
* The name of the list in which the item was presented to the user.
|
|
78
|
+
*/
|
|
79
|
+
item_list_name?: string
|
|
80
|
+
/**
|
|
81
|
+
* Variant of the product (e.g. Black).
|
|
82
|
+
*/
|
|
83
|
+
item_variant?: string
|
|
84
|
+
/**
|
|
85
|
+
* The location associated with the item.
|
|
86
|
+
*/
|
|
87
|
+
location_id?: string
|
|
88
|
+
/**
|
|
89
|
+
* Price of the product being purchased, in units of the specified currency parameter.
|
|
90
|
+
*/
|
|
91
|
+
price?: number
|
|
92
|
+
/**
|
|
93
|
+
* Item quantity.
|
|
94
|
+
*/
|
|
95
|
+
quantity?: number
|
|
96
|
+
}[]
|
|
97
|
+
/**
|
|
98
|
+
* The user properties to send to Google Analytics 4. You must create user-scoped dimensions to ensure custom properties are picked up by Google. See Google’s [Custom user properties](https://support.google.com/analytics/answer/9269570) to learn how to set and register user properties.
|
|
99
|
+
*/
|
|
100
|
+
user_properties?: {
|
|
101
|
+
[k: string]: unknown
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* The event parameters to send to Google Analytics 4.
|
|
105
|
+
*/
|
|
106
|
+
params?: {
|
|
107
|
+
[k: string]: unknown
|
|
108
|
+
}
|
|
109
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { BrowserActionDefinition } from '@segment/browser-destination-runtime/types'
|
|
2
|
+
import type { Settings } from '../generated-types'
|
|
3
|
+
import type { Payload } from './generated-types'
|
|
4
|
+
|
|
5
|
+
import { user_properties, params, currency, value, user_id, items_multi_products } from '../ga4-properties'
|
|
6
|
+
import { updateUser } from '../ga4-functions'
|
|
7
|
+
|
|
8
|
+
const action: BrowserActionDefinition<Settings, Function, Payload> = {
|
|
9
|
+
title: 'View Cart',
|
|
10
|
+
description: 'This event signifies that a user viewed their cart.',
|
|
11
|
+
defaultSubscription: 'type = "track" and event = "Cart Viewed"',
|
|
12
|
+
platform: 'web',
|
|
13
|
+
fields: {
|
|
14
|
+
user_id: user_id,
|
|
15
|
+
currency: currency,
|
|
16
|
+
value: value,
|
|
17
|
+
items: {
|
|
18
|
+
...items_multi_products,
|
|
19
|
+
required: true
|
|
20
|
+
},
|
|
21
|
+
user_properties: user_properties,
|
|
22
|
+
params: params
|
|
23
|
+
},
|
|
24
|
+
perform: (gtag, { payload }) => {
|
|
25
|
+
updateUser(payload.user_id, payload.user_properties, gtag)
|
|
26
|
+
|
|
27
|
+
gtag('event', 'view_cart', {
|
|
28
|
+
currency: payload.currency,
|
|
29
|
+
value: payload.value,
|
|
30
|
+
items: payload.items,
|
|
31
|
+
...payload.params
|
|
32
|
+
})
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export default action
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
// Generated file. DO NOT MODIFY IT BY HAND.
|
|
2
|
+
|
|
3
|
+
export interface Payload {
|
|
4
|
+
/**
|
|
5
|
+
* A unique identifier for a user. See Google's [User-ID for cross-platform analysis](https://support.google.com/analytics/answer/9213390) and [Reporting: deduplicate user counts](https://support.google.com/analytics/answer/9355949?hl=en) documentation for more information on this identifier.
|
|
6
|
+
*/
|
|
7
|
+
user_id?: string
|
|
8
|
+
/**
|
|
9
|
+
* Currency of the items associated with the event, in 3-letter ISO 4217 format.
|
|
10
|
+
*/
|
|
11
|
+
currency?: string
|
|
12
|
+
/**
|
|
13
|
+
* The monetary value of the event.
|
|
14
|
+
*/
|
|
15
|
+
value?: number
|
|
16
|
+
/**
|
|
17
|
+
* The list of products purchased.
|
|
18
|
+
*/
|
|
19
|
+
items: {
|
|
20
|
+
/**
|
|
21
|
+
* Identifier for the product being purchased.
|
|
22
|
+
*/
|
|
23
|
+
item_id?: string
|
|
24
|
+
/**
|
|
25
|
+
* Name of the product being purchased.
|
|
26
|
+
*/
|
|
27
|
+
item_name?: string
|
|
28
|
+
/**
|
|
29
|
+
* A product affiliation to designate a supplying company or brick and mortar store location.
|
|
30
|
+
*/
|
|
31
|
+
affiliation?: string
|
|
32
|
+
/**
|
|
33
|
+
* Coupon code used for a purchase.
|
|
34
|
+
*/
|
|
35
|
+
coupon?: string
|
|
36
|
+
/**
|
|
37
|
+
* Currency of the purchase or items associated with the event, in 3-letter ISO 4217 format.
|
|
38
|
+
*/
|
|
39
|
+
currency?: string
|
|
40
|
+
/**
|
|
41
|
+
* Monetary value of discount associated with a purchase.
|
|
42
|
+
*/
|
|
43
|
+
discount?: number
|
|
44
|
+
/**
|
|
45
|
+
* The index/position of the item in a list.
|
|
46
|
+
*/
|
|
47
|
+
index?: number
|
|
48
|
+
/**
|
|
49
|
+
* Brand associated with the product.
|
|
50
|
+
*/
|
|
51
|
+
item_brand?: string
|
|
52
|
+
/**
|
|
53
|
+
* Product category.
|
|
54
|
+
*/
|
|
55
|
+
item_category?: string
|
|
56
|
+
/**
|
|
57
|
+
* Product category 2.
|
|
58
|
+
*/
|
|
59
|
+
item_category2?: string
|
|
60
|
+
/**
|
|
61
|
+
* Product category 3.
|
|
62
|
+
*/
|
|
63
|
+
item_category3?: string
|
|
64
|
+
/**
|
|
65
|
+
* Product category 4.
|
|
66
|
+
*/
|
|
67
|
+
item_category4?: string
|
|
68
|
+
/**
|
|
69
|
+
* Product category 5.
|
|
70
|
+
*/
|
|
71
|
+
item_category5?: string
|
|
72
|
+
/**
|
|
73
|
+
* The ID of the list in which the item was presented to the user.
|
|
74
|
+
*/
|
|
75
|
+
item_list_id?: string
|
|
76
|
+
/**
|
|
77
|
+
* The name of the list in which the item was presented to the user.
|
|
78
|
+
*/
|
|
79
|
+
item_list_name?: string
|
|
80
|
+
/**
|
|
81
|
+
* Variant of the product (e.g. Black).
|
|
82
|
+
*/
|
|
83
|
+
item_variant?: string
|
|
84
|
+
/**
|
|
85
|
+
* The location associated with the item.
|
|
86
|
+
*/
|
|
87
|
+
location_id?: string
|
|
88
|
+
/**
|
|
89
|
+
* Price of the product being purchased, in units of the specified currency parameter.
|
|
90
|
+
*/
|
|
91
|
+
price?: number
|
|
92
|
+
/**
|
|
93
|
+
* Item quantity.
|
|
94
|
+
*/
|
|
95
|
+
quantity?: number
|
|
96
|
+
}[]
|
|
97
|
+
/**
|
|
98
|
+
* The user properties to send to Google Analytics 4. You must create user-scoped dimensions to ensure custom properties are picked up by Google. See Google’s [Custom user properties](https://support.google.com/analytics/answer/9269570) to learn how to set and register user properties.
|
|
99
|
+
*/
|
|
100
|
+
user_properties?: {
|
|
101
|
+
[k: string]: unknown
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* The event parameters to send to Google Analytics 4.
|
|
105
|
+
*/
|
|
106
|
+
params?: {
|
|
107
|
+
[k: string]: unknown
|
|
108
|
+
}
|
|
109
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { BrowserActionDefinition } from '@segment/browser-destination-runtime/types'
|
|
2
|
+
import type { Settings } from '../generated-types'
|
|
3
|
+
import type { Payload } from './generated-types'
|
|
4
|
+
|
|
5
|
+
import { user_properties, params, currency, user_id, value, items_single_products } from '../ga4-properties'
|
|
6
|
+
import { updateUser } from '../ga4-functions'
|
|
7
|
+
|
|
8
|
+
const action: BrowserActionDefinition<Settings, Function, Payload> = {
|
|
9
|
+
title: 'View Item',
|
|
10
|
+
description:
|
|
11
|
+
'This event signifies that some content was shown to the user. Use this event to discover the most popular items viewed.',
|
|
12
|
+
defaultSubscription: 'type = "track" and event = "Product Viewed"',
|
|
13
|
+
platform: 'web',
|
|
14
|
+
fields: {
|
|
15
|
+
user_id: user_id,
|
|
16
|
+
currency: currency,
|
|
17
|
+
value: value,
|
|
18
|
+
items: {
|
|
19
|
+
...items_single_products,
|
|
20
|
+
required: true
|
|
21
|
+
},
|
|
22
|
+
user_properties: user_properties,
|
|
23
|
+
params: params
|
|
24
|
+
},
|
|
25
|
+
perform: (gtag, { payload }) => {
|
|
26
|
+
updateUser(payload.user_id, payload.user_properties, gtag)
|
|
27
|
+
|
|
28
|
+
gtag('event', 'view_item', {
|
|
29
|
+
currency: payload.currency,
|
|
30
|
+
value: payload.value,
|
|
31
|
+
items: payload.items,
|
|
32
|
+
...payload.params
|
|
33
|
+
})
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export default action
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
// Generated file. DO NOT MODIFY IT BY HAND.
|
|
2
|
+
|
|
3
|
+
export interface Payload {
|
|
4
|
+
/**
|
|
5
|
+
* A unique identifier for a user. See Google's [User-ID for cross-platform analysis](https://support.google.com/analytics/answer/9213390) and [Reporting: deduplicate user counts](https://support.google.com/analytics/answer/9355949?hl=en) documentation for more information on this identifier.
|
|
6
|
+
*/
|
|
7
|
+
user_id?: string
|
|
8
|
+
/**
|
|
9
|
+
* The ID of the list in which the item was presented to the user.
|
|
10
|
+
*/
|
|
11
|
+
item_list_id?: string
|
|
12
|
+
/**
|
|
13
|
+
* The name of the list in which the item was presented to the user.
|
|
14
|
+
*/
|
|
15
|
+
item_list_name?: string
|
|
16
|
+
/**
|
|
17
|
+
* The list of products purchased.
|
|
18
|
+
*/
|
|
19
|
+
items: {
|
|
20
|
+
/**
|
|
21
|
+
* Identifier for the product being purchased.
|
|
22
|
+
*/
|
|
23
|
+
item_id?: string
|
|
24
|
+
/**
|
|
25
|
+
* Name of the product being purchased.
|
|
26
|
+
*/
|
|
27
|
+
item_name?: string
|
|
28
|
+
/**
|
|
29
|
+
* A product affiliation to designate a supplying company or brick and mortar store location.
|
|
30
|
+
*/
|
|
31
|
+
affiliation?: string
|
|
32
|
+
/**
|
|
33
|
+
* Coupon code used for a purchase.
|
|
34
|
+
*/
|
|
35
|
+
coupon?: string
|
|
36
|
+
/**
|
|
37
|
+
* Currency of the purchase or items associated with the event, in 3-letter ISO 4217 format.
|
|
38
|
+
*/
|
|
39
|
+
currency?: string
|
|
40
|
+
/**
|
|
41
|
+
* Monetary value of discount associated with a purchase.
|
|
42
|
+
*/
|
|
43
|
+
discount?: number
|
|
44
|
+
/**
|
|
45
|
+
* The index/position of the item in a list.
|
|
46
|
+
*/
|
|
47
|
+
index?: number
|
|
48
|
+
/**
|
|
49
|
+
* Brand associated with the product.
|
|
50
|
+
*/
|
|
51
|
+
item_brand?: string
|
|
52
|
+
/**
|
|
53
|
+
* Product category.
|
|
54
|
+
*/
|
|
55
|
+
item_category?: string
|
|
56
|
+
/**
|
|
57
|
+
* Product category 2.
|
|
58
|
+
*/
|
|
59
|
+
item_category2?: string
|
|
60
|
+
/**
|
|
61
|
+
* Product category 3.
|
|
62
|
+
*/
|
|
63
|
+
item_category3?: string
|
|
64
|
+
/**
|
|
65
|
+
* Product category 4.
|
|
66
|
+
*/
|
|
67
|
+
item_category4?: string
|
|
68
|
+
/**
|
|
69
|
+
* Product category 5.
|
|
70
|
+
*/
|
|
71
|
+
item_category5?: string
|
|
72
|
+
/**
|
|
73
|
+
* The ID of the list in which the item was presented to the user.
|
|
74
|
+
*/
|
|
75
|
+
item_list_id?: string
|
|
76
|
+
/**
|
|
77
|
+
* The name of the list in which the item was presented to the user.
|
|
78
|
+
*/
|
|
79
|
+
item_list_name?: string
|
|
80
|
+
/**
|
|
81
|
+
* Variant of the product (e.g. Black).
|
|
82
|
+
*/
|
|
83
|
+
item_variant?: string
|
|
84
|
+
/**
|
|
85
|
+
* The location associated with the item.
|
|
86
|
+
*/
|
|
87
|
+
location_id?: string
|
|
88
|
+
/**
|
|
89
|
+
* Price of the product being purchased, in units of the specified currency parameter.
|
|
90
|
+
*/
|
|
91
|
+
price?: number
|
|
92
|
+
/**
|
|
93
|
+
* Item quantity.
|
|
94
|
+
*/
|
|
95
|
+
quantity?: number
|
|
96
|
+
}[]
|
|
97
|
+
/**
|
|
98
|
+
* The user properties to send to Google Analytics 4. You must create user-scoped dimensions to ensure custom properties are picked up by Google. See Google’s [Custom user properties](https://support.google.com/analytics/answer/9269570) to learn how to set and register user properties.
|
|
99
|
+
*/
|
|
100
|
+
user_properties?: {
|
|
101
|
+
[k: string]: unknown
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* The event parameters to send to Google Analytics 4.
|
|
105
|
+
*/
|
|
106
|
+
params?: {
|
|
107
|
+
[k: string]: unknown
|
|
108
|
+
}
|
|
109
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { BrowserActionDefinition } from '@segment/browser-destination-runtime/types'
|
|
2
|
+
import type { Settings } from '../generated-types'
|
|
3
|
+
import type { Payload } from './generated-types'
|
|
4
|
+
|
|
5
|
+
import { user_properties, params, user_id, items_multi_products, item_list_name, item_list_id } from '../ga4-properties'
|
|
6
|
+
import { updateUser } from '../ga4-functions'
|
|
7
|
+
|
|
8
|
+
const action: BrowserActionDefinition<Settings, Function, Payload> = {
|
|
9
|
+
title: 'View Item List',
|
|
10
|
+
description: 'Log this event when the user has been presented with a list of items of a certain category.',
|
|
11
|
+
platform: 'web',
|
|
12
|
+
defaultSubscription: 'type = "track" and event = "Promotion Viewed"',
|
|
13
|
+
fields: {
|
|
14
|
+
user_id: user_id,
|
|
15
|
+
item_list_id: item_list_id,
|
|
16
|
+
item_list_name: item_list_name,
|
|
17
|
+
items: {
|
|
18
|
+
...items_multi_products,
|
|
19
|
+
required: true
|
|
20
|
+
},
|
|
21
|
+
user_properties: user_properties,
|
|
22
|
+
params: params
|
|
23
|
+
},
|
|
24
|
+
perform: (gtag, { payload }) => {
|
|
25
|
+
updateUser(payload.user_id, payload.user_properties, gtag)
|
|
26
|
+
|
|
27
|
+
gtag('event', 'view_item_list', {
|
|
28
|
+
item_list_id: payload.item_list_id,
|
|
29
|
+
item_list_name: payload.item_list_name,
|
|
30
|
+
items: payload.items,
|
|
31
|
+
...payload.params
|
|
32
|
+
})
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export default action
|