@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,137 @@
|
|
|
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 name of the promotional creative.
|
|
10
|
+
*/
|
|
11
|
+
creative_name?: string
|
|
12
|
+
/**
|
|
13
|
+
* The name of the promotional creative slot associated with the event.
|
|
14
|
+
*/
|
|
15
|
+
creative_slot?: string
|
|
16
|
+
/**
|
|
17
|
+
* The ID of the location.
|
|
18
|
+
*/
|
|
19
|
+
location_id?: string
|
|
20
|
+
/**
|
|
21
|
+
* The ID of the promotion associated with the event.
|
|
22
|
+
*/
|
|
23
|
+
promotion_id?: string
|
|
24
|
+
/**
|
|
25
|
+
* The name of the promotion associated with the event.
|
|
26
|
+
*/
|
|
27
|
+
promotion_name?: string
|
|
28
|
+
/**
|
|
29
|
+
* The list of products purchased.
|
|
30
|
+
*/
|
|
31
|
+
items: {
|
|
32
|
+
/**
|
|
33
|
+
* Identifier for the product being purchased.
|
|
34
|
+
*/
|
|
35
|
+
item_id?: string
|
|
36
|
+
/**
|
|
37
|
+
* Name of the product being purchased.
|
|
38
|
+
*/
|
|
39
|
+
item_name?: string
|
|
40
|
+
/**
|
|
41
|
+
* A product affiliation to designate a supplying company or brick and mortar store location.
|
|
42
|
+
*/
|
|
43
|
+
affiliation?: string
|
|
44
|
+
/**
|
|
45
|
+
* Coupon code used for a purchase.
|
|
46
|
+
*/
|
|
47
|
+
coupon?: string
|
|
48
|
+
/**
|
|
49
|
+
* Currency of the purchase or items associated with the event, in 3-letter ISO 4217 format.
|
|
50
|
+
*/
|
|
51
|
+
currency?: string
|
|
52
|
+
/**
|
|
53
|
+
* Monetary value of discount associated with a purchase.
|
|
54
|
+
*/
|
|
55
|
+
discount?: number
|
|
56
|
+
/**
|
|
57
|
+
* The index/position of the item in a list.
|
|
58
|
+
*/
|
|
59
|
+
index?: number
|
|
60
|
+
/**
|
|
61
|
+
* Brand associated with the product.
|
|
62
|
+
*/
|
|
63
|
+
item_brand?: string
|
|
64
|
+
/**
|
|
65
|
+
* Product category.
|
|
66
|
+
*/
|
|
67
|
+
item_category?: string
|
|
68
|
+
/**
|
|
69
|
+
* Product category 2.
|
|
70
|
+
*/
|
|
71
|
+
item_category2?: string
|
|
72
|
+
/**
|
|
73
|
+
* Product category 3.
|
|
74
|
+
*/
|
|
75
|
+
item_category3?: string
|
|
76
|
+
/**
|
|
77
|
+
* Product category 4.
|
|
78
|
+
*/
|
|
79
|
+
item_category4?: string
|
|
80
|
+
/**
|
|
81
|
+
* Product category 5.
|
|
82
|
+
*/
|
|
83
|
+
item_category5?: string
|
|
84
|
+
/**
|
|
85
|
+
* The ID of the list in which the item was presented to the user.
|
|
86
|
+
*/
|
|
87
|
+
item_list_id?: string
|
|
88
|
+
/**
|
|
89
|
+
* The name of the list in which the item was presented to the user.
|
|
90
|
+
*/
|
|
91
|
+
item_list_name?: string
|
|
92
|
+
/**
|
|
93
|
+
* Variant of the product (e.g. Black).
|
|
94
|
+
*/
|
|
95
|
+
item_variant?: string
|
|
96
|
+
/**
|
|
97
|
+
* The location associated with the item.
|
|
98
|
+
*/
|
|
99
|
+
location_id?: string
|
|
100
|
+
/**
|
|
101
|
+
* Price of the product being purchased, in units of the specified currency parameter.
|
|
102
|
+
*/
|
|
103
|
+
price?: number
|
|
104
|
+
/**
|
|
105
|
+
* Item quantity.
|
|
106
|
+
*/
|
|
107
|
+
quantity?: number
|
|
108
|
+
/**
|
|
109
|
+
* The name of the promotional creative.
|
|
110
|
+
*/
|
|
111
|
+
creative_name?: string
|
|
112
|
+
/**
|
|
113
|
+
* The name of the promotional creative slot associated with the event.
|
|
114
|
+
*/
|
|
115
|
+
creative_slot?: string
|
|
116
|
+
/**
|
|
117
|
+
* The name of the promotion associated with the event.
|
|
118
|
+
*/
|
|
119
|
+
promotion_name?: string
|
|
120
|
+
/**
|
|
121
|
+
* The ID of the promotion associated with the event.
|
|
122
|
+
*/
|
|
123
|
+
promotion_id?: string
|
|
124
|
+
}[]
|
|
125
|
+
/**
|
|
126
|
+
* 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.
|
|
127
|
+
*/
|
|
128
|
+
user_properties?: {
|
|
129
|
+
[k: string]: unknown
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* The event parameters to send to Google Analytics 4.
|
|
133
|
+
*/
|
|
134
|
+
params?: {
|
|
135
|
+
[k: string]: unknown
|
|
136
|
+
}
|
|
137
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
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 {
|
|
5
|
+
creative_name,
|
|
6
|
+
creative_slot,
|
|
7
|
+
promotion_id,
|
|
8
|
+
promotion_name,
|
|
9
|
+
user_id,
|
|
10
|
+
minimal_items,
|
|
11
|
+
items_single_products,
|
|
12
|
+
params,
|
|
13
|
+
user_properties,
|
|
14
|
+
location_id
|
|
15
|
+
} from '../ga4-properties'
|
|
16
|
+
import { updateUser } from '../ga4-functions'
|
|
17
|
+
|
|
18
|
+
const action: BrowserActionDefinition<Settings, Function, Payload> = {
|
|
19
|
+
title: 'View Promotion',
|
|
20
|
+
description: 'This event signifies a promotion was viewed from a list.',
|
|
21
|
+
defaultSubscription: 'type = "track"',
|
|
22
|
+
platform: 'web',
|
|
23
|
+
fields: {
|
|
24
|
+
user_id: user_id,
|
|
25
|
+
creative_name: creative_name,
|
|
26
|
+
creative_slot: { ...creative_slot, default: { '@path': '$.properties.creative' } },
|
|
27
|
+
location_id: location_id,
|
|
28
|
+
promotion_id: { ...promotion_id, default: { '@path': '$.properties.promotion_id' } },
|
|
29
|
+
promotion_name: { ...promotion_name, default: { '@path': '$.properties.name' } },
|
|
30
|
+
items: {
|
|
31
|
+
...items_single_products,
|
|
32
|
+
required: true,
|
|
33
|
+
properties: {
|
|
34
|
+
...minimal_items.properties,
|
|
35
|
+
creative_name: {
|
|
36
|
+
...creative_name
|
|
37
|
+
},
|
|
38
|
+
creative_slot: {
|
|
39
|
+
...creative_slot
|
|
40
|
+
},
|
|
41
|
+
promotion_name: {
|
|
42
|
+
...promotion_name
|
|
43
|
+
},
|
|
44
|
+
promotion_id: {
|
|
45
|
+
...promotion_id
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
user_properties: user_properties,
|
|
50
|
+
params: params
|
|
51
|
+
},
|
|
52
|
+
perform: (gtag, { payload }) => {
|
|
53
|
+
updateUser(payload.user_id, payload.user_properties, gtag)
|
|
54
|
+
|
|
55
|
+
gtag('event', 'view_promotion', {
|
|
56
|
+
creative_name: payload.creative_name,
|
|
57
|
+
creative_slot: payload.creative_slot,
|
|
58
|
+
location_id: payload.location_id,
|
|
59
|
+
promotion_id: payload.promotion_id,
|
|
60
|
+
promotion_name: payload.promotion_name,
|
|
61
|
+
items: payload.items,
|
|
62
|
+
...payload.params
|
|
63
|
+
})
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export default action
|