@segment/analytics-browser-actions-google-analytics-4 1.32.0 → 1.34.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/dist/cjs/addPaymentInfo/generated-types.d.ts +1 -0
- package/dist/cjs/addPaymentInfo/index.js +4 -2
- package/dist/cjs/addPaymentInfo/index.js.map +1 -1
- package/dist/cjs/addToCart/generated-types.d.ts +1 -0
- package/dist/cjs/addToCart/index.js +4 -2
- package/dist/cjs/addToCart/index.js.map +1 -1
- package/dist/cjs/addToWishlist/generated-types.d.ts +1 -0
- package/dist/cjs/addToWishlist/index.js +4 -2
- package/dist/cjs/addToWishlist/index.js.map +1 -1
- package/dist/cjs/beginCheckout/generated-types.d.ts +1 -0
- package/dist/cjs/beginCheckout/index.js +4 -2
- package/dist/cjs/beginCheckout/index.js.map +1 -1
- package/dist/cjs/customEvent/generated-types.d.ts +1 -0
- package/dist/cjs/customEvent/index.js +4 -2
- package/dist/cjs/customEvent/index.js.map +1 -1
- package/dist/cjs/ga4-properties.d.ts +1 -0
- package/dist/cjs/ga4-properties.js +7 -1
- package/dist/cjs/ga4-properties.js.map +1 -1
- package/dist/cjs/generateLead/generated-types.d.ts +1 -0
- package/dist/cjs/generateLead/index.js +4 -2
- package/dist/cjs/generateLead/index.js.map +1 -1
- package/dist/cjs/login/generated-types.d.ts +1 -0
- package/dist/cjs/login/index.js +4 -2
- package/dist/cjs/login/index.js.map +1 -1
- package/dist/cjs/purchase/generated-types.d.ts +1 -0
- package/dist/cjs/purchase/index.js +4 -2
- package/dist/cjs/purchase/index.js.map +1 -1
- package/dist/cjs/refund/generated-types.d.ts +1 -0
- package/dist/cjs/refund/index.js +4 -2
- package/dist/cjs/refund/index.js.map +1 -1
- package/dist/cjs/removeFromCart/generated-types.d.ts +1 -0
- package/dist/cjs/removeFromCart/index.js +4 -2
- package/dist/cjs/removeFromCart/index.js.map +1 -1
- package/dist/cjs/search/generated-types.d.ts +1 -0
- package/dist/cjs/search/index.js +4 -2
- package/dist/cjs/search/index.js.map +1 -1
- package/dist/cjs/selectItem/generated-types.d.ts +1 -0
- package/dist/cjs/selectItem/index.js +4 -2
- package/dist/cjs/selectItem/index.js.map +1 -1
- package/dist/cjs/selectPromotion/generated-types.d.ts +1 -0
- package/dist/cjs/selectPromotion/index.js +4 -2
- package/dist/cjs/selectPromotion/index.js.map +1 -1
- package/dist/cjs/signUp/generated-types.d.ts +1 -0
- package/dist/cjs/signUp/index.js +4 -2
- package/dist/cjs/signUp/index.js.map +1 -1
- package/dist/cjs/viewCart/generated-types.d.ts +1 -0
- package/dist/cjs/viewCart/index.js +4 -2
- package/dist/cjs/viewCart/index.js.map +1 -1
- package/dist/cjs/viewItem/generated-types.d.ts +1 -0
- package/dist/cjs/viewItem/index.js +4 -2
- package/dist/cjs/viewItem/index.js.map +1 -1
- package/dist/cjs/viewItemList/generated-types.d.ts +1 -0
- package/dist/cjs/viewItemList/index.js +4 -2
- package/dist/cjs/viewItemList/index.js.map +1 -1
- package/dist/cjs/viewPromotion/generated-types.d.ts +1 -0
- package/dist/cjs/viewPromotion/index.js +4 -2
- package/dist/cjs/viewPromotion/index.js.map +1 -1
- package/dist/esm/addPaymentInfo/generated-types.d.ts +1 -0
- package/dist/esm/addPaymentInfo/index.js +5 -3
- package/dist/esm/addPaymentInfo/index.js.map +1 -1
- package/dist/esm/addToCart/generated-types.d.ts +1 -0
- package/dist/esm/addToCart/index.js +5 -3
- package/dist/esm/addToCart/index.js.map +1 -1
- package/dist/esm/addToWishlist/generated-types.d.ts +1 -0
- package/dist/esm/addToWishlist/index.js +5 -3
- package/dist/esm/addToWishlist/index.js.map +1 -1
- package/dist/esm/beginCheckout/generated-types.d.ts +1 -0
- package/dist/esm/beginCheckout/index.js +5 -3
- package/dist/esm/beginCheckout/index.js.map +1 -1
- package/dist/esm/customEvent/generated-types.d.ts +1 -0
- package/dist/esm/customEvent/index.js +5 -3
- package/dist/esm/customEvent/index.js.map +1 -1
- package/dist/esm/ga4-properties.d.ts +1 -0
- package/dist/esm/ga4-properties.js +6 -0
- package/dist/esm/ga4-properties.js.map +1 -1
- package/dist/esm/generateLead/generated-types.d.ts +1 -0
- package/dist/esm/generateLead/index.js +5 -3
- package/dist/esm/generateLead/index.js.map +1 -1
- package/dist/esm/login/generated-types.d.ts +1 -0
- package/dist/esm/login/index.js +5 -3
- package/dist/esm/login/index.js.map +1 -1
- package/dist/esm/purchase/generated-types.d.ts +1 -0
- package/dist/esm/purchase/index.js +5 -3
- package/dist/esm/purchase/index.js.map +1 -1
- package/dist/esm/refund/generated-types.d.ts +1 -0
- package/dist/esm/refund/index.js +5 -3
- package/dist/esm/refund/index.js.map +1 -1
- package/dist/esm/removeFromCart/generated-types.d.ts +1 -0
- package/dist/esm/removeFromCart/index.js +5 -3
- package/dist/esm/removeFromCart/index.js.map +1 -1
- package/dist/esm/search/generated-types.d.ts +1 -0
- package/dist/esm/search/index.js +5 -3
- package/dist/esm/search/index.js.map +1 -1
- package/dist/esm/selectItem/generated-types.d.ts +1 -0
- package/dist/esm/selectItem/index.js +5 -3
- package/dist/esm/selectItem/index.js.map +1 -1
- package/dist/esm/selectPromotion/generated-types.d.ts +1 -0
- package/dist/esm/selectPromotion/index.js +5 -3
- package/dist/esm/selectPromotion/index.js.map +1 -1
- package/dist/esm/signUp/generated-types.d.ts +1 -0
- package/dist/esm/signUp/index.js +5 -3
- package/dist/esm/signUp/index.js.map +1 -1
- package/dist/esm/viewCart/generated-types.d.ts +1 -0
- package/dist/esm/viewCart/index.js +5 -3
- package/dist/esm/viewCart/index.js.map +1 -1
- package/dist/esm/viewItem/generated-types.d.ts +1 -0
- package/dist/esm/viewItem/index.js +5 -3
- package/dist/esm/viewItem/index.js.map +1 -1
- package/dist/esm/viewItemList/generated-types.d.ts +1 -0
- package/dist/esm/viewItemList/index.js +5 -3
- package/dist/esm/viewItemList/index.js.map +1 -1
- package/dist/esm/viewPromotion/generated-types.d.ts +1 -0
- package/dist/esm/viewPromotion/index.js +5 -3
- package/dist/esm/viewPromotion/index.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +4 -4
- package/src/__tests__/addPaymentInfo.test.ts +74 -2
- package/src/__tests__/addToCart.test.ts +67 -2
- package/src/__tests__/addToWishlist.test.ts +68 -2
- package/src/__tests__/beginCheckout.test.ts +72 -2
- package/src/__tests__/customEvent.test.ts +62 -2
- package/src/__tests__/generateLead.test.ts +50 -2
- package/src/__tests__/login.test.ts +47 -2
- package/src/__tests__/purchase.test.ts +71 -2
- package/src/__tests__/refund.test.ts +70 -2
- package/src/__tests__/removeFromCart.test.ts +69 -2
- package/src/__tests__/search.test.ts +48 -2
- package/src/__tests__/selectItem.test.ts +69 -2
- package/src/__tests__/selectPromotion.test.ts +81 -2
- package/src/__tests__/signUp.test.ts +42 -2
- package/src/__tests__/viewCart.test.ts +69 -2
- package/src/__tests__/viewItem.test.ts +68 -2
- package/src/__tests__/viewItemList.test.ts +70 -2
- package/src/__tests__/viewPromotion.test.ts +80 -2
- package/src/addPaymentInfo/generated-types.ts +4 -0
- package/src/addPaymentInfo/index.ts +6 -3
- package/src/addToCart/generated-types.ts +4 -0
- package/src/addToCart/index.ts +5 -3
- package/src/addToWishlist/generated-types.ts +4 -0
- package/src/addToWishlist/index.ts +5 -3
- package/src/beginCheckout/generated-types.ts +4 -0
- package/src/beginCheckout/index.ts +14 -3
- package/src/customEvent/generated-types.ts +4 -0
- package/src/customEvent/index.ts +5 -3
- package/src/ga4-properties.ts +7 -0
- package/src/generateLead/generated-types.ts +4 -0
- package/src/generateLead/index.ts +5 -3
- package/src/login/generated-types.ts +4 -0
- package/src/login/index.ts +5 -3
- package/src/purchase/generated-types.ts +4 -0
- package/src/purchase/index.ts +6 -3
- package/src/refund/generated-types.ts +4 -0
- package/src/refund/index.ts +6 -3
- package/src/removeFromCart/generated-types.ts +4 -0
- package/src/removeFromCart/index.ts +5 -3
- package/src/search/generated-types.ts +4 -0
- package/src/search/index.ts +5 -3
- package/src/selectItem/generated-types.ts +4 -0
- package/src/selectItem/index.ts +6 -3
- package/src/selectPromotion/generated-types.ts +4 -0
- package/src/selectPromotion/index.ts +6 -3
- package/src/signUp/generated-types.ts +4 -0
- package/src/signUp/index.ts +5 -3
- package/src/viewCart/generated-types.ts +4 -0
- package/src/viewCart/index.ts +5 -3
- package/src/viewItem/generated-types.ts +4 -0
- package/src/viewItem/index.ts +5 -3
- package/src/viewItemList/generated-types.ts +4 -0
- package/src/viewItemList/index.ts +13 -3
- package/src/viewPromotion/generated-types.ts +4 -0
- package/src/viewPromotion/index.ts +6 -3
|
@@ -15,6 +15,9 @@ const subscriptions: Subscription[] = [
|
|
|
15
15
|
value: {
|
|
16
16
|
'@path': '$.properties.value'
|
|
17
17
|
},
|
|
18
|
+
send_to: {
|
|
19
|
+
'@path': '$.properties.send_to'
|
|
20
|
+
},
|
|
18
21
|
items: [
|
|
19
22
|
{
|
|
20
23
|
item_name: {
|
|
@@ -61,13 +64,14 @@ describe('GoogleAnalytics4Web.addToCart', () => {
|
|
|
61
64
|
await trackEventPlugin.load(Context.system(), {} as Analytics)
|
|
62
65
|
})
|
|
63
66
|
|
|
64
|
-
test('GA4 addToCart Event', async () => {
|
|
67
|
+
test('GA4 addToCart Event when send to is false', async () => {
|
|
65
68
|
const context = new Context({
|
|
66
69
|
event: 'Add To Cart',
|
|
67
70
|
type: 'track',
|
|
68
71
|
properties: {
|
|
69
72
|
currency: 'USD',
|
|
70
73
|
value: 10,
|
|
74
|
+
send_to: false,
|
|
71
75
|
products: [
|
|
72
76
|
{
|
|
73
77
|
product_id: '12345',
|
|
@@ -85,7 +89,68 @@ describe('GoogleAnalytics4Web.addToCart', () => {
|
|
|
85
89
|
expect.objectContaining({
|
|
86
90
|
currency: 'USD',
|
|
87
91
|
items: [{ currency: 'USD', item_id: '12345', item_name: 'Monopoly: 3rd Edition' }],
|
|
88
|
-
value: 10
|
|
92
|
+
value: 10,
|
|
93
|
+
send_to: 'default'
|
|
94
|
+
})
|
|
95
|
+
)
|
|
96
|
+
})
|
|
97
|
+
test('GA4 addToCart Event when send to is true', async () => {
|
|
98
|
+
const context = new Context({
|
|
99
|
+
event: 'Add To Cart',
|
|
100
|
+
type: 'track',
|
|
101
|
+
properties: {
|
|
102
|
+
currency: 'USD',
|
|
103
|
+
value: 10,
|
|
104
|
+
send_to: true,
|
|
105
|
+
products: [
|
|
106
|
+
{
|
|
107
|
+
product_id: '12345',
|
|
108
|
+
name: 'Monopoly: 3rd Edition',
|
|
109
|
+
currency: 'USD'
|
|
110
|
+
}
|
|
111
|
+
]
|
|
112
|
+
}
|
|
113
|
+
})
|
|
114
|
+
await addToCartEvent.track?.(context)
|
|
115
|
+
|
|
116
|
+
expect(mockGA4).toHaveBeenCalledWith(
|
|
117
|
+
expect.anything(),
|
|
118
|
+
expect.stringContaining('add_to_cart'),
|
|
119
|
+
expect.objectContaining({
|
|
120
|
+
currency: 'USD',
|
|
121
|
+
items: [{ currency: 'USD', item_id: '12345', item_name: 'Monopoly: 3rd Edition' }],
|
|
122
|
+
value: 10,
|
|
123
|
+
send_to: settings.measurementID
|
|
124
|
+
})
|
|
125
|
+
)
|
|
126
|
+
})
|
|
127
|
+
|
|
128
|
+
test('GA4 addToCart Event when send to is undefined', async () => {
|
|
129
|
+
const context = new Context({
|
|
130
|
+
event: 'Add To Cart',
|
|
131
|
+
type: 'track',
|
|
132
|
+
properties: {
|
|
133
|
+
currency: 'USD',
|
|
134
|
+
value: 10,
|
|
135
|
+
products: [
|
|
136
|
+
{
|
|
137
|
+
product_id: '12345',
|
|
138
|
+
name: 'Monopoly: 3rd Edition',
|
|
139
|
+
currency: 'USD'
|
|
140
|
+
}
|
|
141
|
+
]
|
|
142
|
+
}
|
|
143
|
+
})
|
|
144
|
+
await addToCartEvent.track?.(context)
|
|
145
|
+
|
|
146
|
+
expect(mockGA4).toHaveBeenCalledWith(
|
|
147
|
+
expect.anything(),
|
|
148
|
+
expect.stringContaining('add_to_cart'),
|
|
149
|
+
expect.objectContaining({
|
|
150
|
+
currency: 'USD',
|
|
151
|
+
items: [{ currency: 'USD', item_id: '12345', item_name: 'Monopoly: 3rd Edition' }],
|
|
152
|
+
value: 10,
|
|
153
|
+
send_to: 'default'
|
|
89
154
|
})
|
|
90
155
|
)
|
|
91
156
|
})
|
|
@@ -15,6 +15,9 @@ const subscriptions: Subscription[] = [
|
|
|
15
15
|
value: {
|
|
16
16
|
'@path': '$.properties.value'
|
|
17
17
|
},
|
|
18
|
+
send_to: {
|
|
19
|
+
'@path': '$.properties.send_to'
|
|
20
|
+
},
|
|
18
21
|
items: [
|
|
19
22
|
{
|
|
20
23
|
item_name: {
|
|
@@ -61,13 +64,45 @@ describe('GoogleAnalytics4Web.addToWishlist', () => {
|
|
|
61
64
|
await trackEventPlugin.load(Context.system(), {} as Analytics)
|
|
62
65
|
})
|
|
63
66
|
|
|
64
|
-
test('Track call without parameters', async () => {
|
|
67
|
+
test('Track call without parameters when send to is false', async () => {
|
|
68
|
+
const context = new Context({
|
|
69
|
+
event: 'Add To Wishlist',
|
|
70
|
+
type: 'track',
|
|
71
|
+
properties: {
|
|
72
|
+
currency: 'USD',
|
|
73
|
+
value: 10,
|
|
74
|
+
send_to: false,
|
|
75
|
+
products: [
|
|
76
|
+
{
|
|
77
|
+
product_id: '12345',
|
|
78
|
+
name: 'Monopoly: 3rd Edition',
|
|
79
|
+
currency: 'USD'
|
|
80
|
+
}
|
|
81
|
+
]
|
|
82
|
+
}
|
|
83
|
+
})
|
|
84
|
+
await addToWishlistEvent.track?.(context)
|
|
85
|
+
|
|
86
|
+
expect(mockGA4).toHaveBeenCalledWith(
|
|
87
|
+
expect.anything(),
|
|
88
|
+
expect.stringContaining('add_to_wishlist'),
|
|
89
|
+
expect.objectContaining({
|
|
90
|
+
currency: 'USD',
|
|
91
|
+
items: [{ currency: 'USD', item_id: '12345', item_name: 'Monopoly: 3rd Edition' }],
|
|
92
|
+
value: 10,
|
|
93
|
+
send_to: 'default'
|
|
94
|
+
})
|
|
95
|
+
)
|
|
96
|
+
})
|
|
97
|
+
|
|
98
|
+
test('Track call without parameters when send to is true', async () => {
|
|
65
99
|
const context = new Context({
|
|
66
100
|
event: 'Add To Wishlist',
|
|
67
101
|
type: 'track',
|
|
68
102
|
properties: {
|
|
69
103
|
currency: 'USD',
|
|
70
104
|
value: 10,
|
|
105
|
+
send_to: true,
|
|
71
106
|
products: [
|
|
72
107
|
{
|
|
73
108
|
product_id: '12345',
|
|
@@ -85,7 +120,38 @@ describe('GoogleAnalytics4Web.addToWishlist', () => {
|
|
|
85
120
|
expect.objectContaining({
|
|
86
121
|
currency: 'USD',
|
|
87
122
|
items: [{ currency: 'USD', item_id: '12345', item_name: 'Monopoly: 3rd Edition' }],
|
|
88
|
-
value: 10
|
|
123
|
+
value: 10,
|
|
124
|
+
send_to: settings.measurementID
|
|
125
|
+
})
|
|
126
|
+
)
|
|
127
|
+
})
|
|
128
|
+
|
|
129
|
+
test('Track call without parameters when send to is undefined', async () => {
|
|
130
|
+
const context = new Context({
|
|
131
|
+
event: 'Add To Wishlist',
|
|
132
|
+
type: 'track',
|
|
133
|
+
properties: {
|
|
134
|
+
currency: 'USD',
|
|
135
|
+
value: 10,
|
|
136
|
+
products: [
|
|
137
|
+
{
|
|
138
|
+
product_id: '12345',
|
|
139
|
+
name: 'Monopoly: 3rd Edition',
|
|
140
|
+
currency: 'USD'
|
|
141
|
+
}
|
|
142
|
+
]
|
|
143
|
+
}
|
|
144
|
+
})
|
|
145
|
+
await addToWishlistEvent.track?.(context)
|
|
146
|
+
|
|
147
|
+
expect(mockGA4).toHaveBeenCalledWith(
|
|
148
|
+
expect.anything(),
|
|
149
|
+
expect.stringContaining('add_to_wishlist'),
|
|
150
|
+
expect.objectContaining({
|
|
151
|
+
currency: 'USD',
|
|
152
|
+
items: [{ currency: 'USD', item_id: '12345', item_name: 'Monopoly: 3rd Edition' }],
|
|
153
|
+
value: 10,
|
|
154
|
+
send_to: 'default'
|
|
89
155
|
})
|
|
90
156
|
)
|
|
91
157
|
})
|
|
@@ -18,6 +18,9 @@ const subscriptions: Subscription[] = [
|
|
|
18
18
|
coupon: {
|
|
19
19
|
'@path': '$.properties.coupon'
|
|
20
20
|
},
|
|
21
|
+
send_to: {
|
|
22
|
+
'@path': '$.properties.send_to'
|
|
23
|
+
},
|
|
21
24
|
items: [
|
|
22
25
|
{
|
|
23
26
|
item_name: {
|
|
@@ -64,7 +67,73 @@ describe('GoogleAnalytics4Web.beginCheckout', () => {
|
|
|
64
67
|
await trackEventPlugin.load(Context.system(), {} as Analytics)
|
|
65
68
|
})
|
|
66
69
|
|
|
67
|
-
test('GA4 beginCheckout Event', async () => {
|
|
70
|
+
test('GA4 beginCheckout Event when send to is false', async () => {
|
|
71
|
+
const context = new Context({
|
|
72
|
+
event: 'Begin Checkout',
|
|
73
|
+
type: 'track',
|
|
74
|
+
properties: {
|
|
75
|
+
currency: 'USD',
|
|
76
|
+
value: 10,
|
|
77
|
+
coupon: 'SUMMER_123',
|
|
78
|
+
payment_method: 'Credit Card',
|
|
79
|
+
send_to: false,
|
|
80
|
+
products: [
|
|
81
|
+
{
|
|
82
|
+
product_id: '12345',
|
|
83
|
+
name: 'Monopoly: 3rd Edition',
|
|
84
|
+
currency: 'USD'
|
|
85
|
+
}
|
|
86
|
+
]
|
|
87
|
+
}
|
|
88
|
+
})
|
|
89
|
+
await beginCheckoutEvent.track?.(context)
|
|
90
|
+
|
|
91
|
+
expect(mockGA4).toHaveBeenCalledWith(
|
|
92
|
+
expect.anything(),
|
|
93
|
+
expect.stringContaining('begin_checkout'),
|
|
94
|
+
expect.objectContaining({
|
|
95
|
+
coupon: 'SUMMER_123',
|
|
96
|
+
currency: 'USD',
|
|
97
|
+
items: [{ currency: 'USD', item_id: '12345', item_name: 'Monopoly: 3rd Edition' }],
|
|
98
|
+
value: 10,
|
|
99
|
+
send_to: 'default'
|
|
100
|
+
})
|
|
101
|
+
)
|
|
102
|
+
})
|
|
103
|
+
test('GA4 beginCheckout Event when send to is true', async () => {
|
|
104
|
+
const context = new Context({
|
|
105
|
+
event: 'Begin Checkout',
|
|
106
|
+
type: 'track',
|
|
107
|
+
properties: {
|
|
108
|
+
currency: 'USD',
|
|
109
|
+
value: 10,
|
|
110
|
+
coupon: 'SUMMER_123',
|
|
111
|
+
payment_method: 'Credit Card',
|
|
112
|
+
send_to: true,
|
|
113
|
+
products: [
|
|
114
|
+
{
|
|
115
|
+
product_id: '12345',
|
|
116
|
+
name: 'Monopoly: 3rd Edition',
|
|
117
|
+
currency: 'USD'
|
|
118
|
+
}
|
|
119
|
+
]
|
|
120
|
+
}
|
|
121
|
+
})
|
|
122
|
+
await beginCheckoutEvent.track?.(context)
|
|
123
|
+
|
|
124
|
+
expect(mockGA4).toHaveBeenCalledWith(
|
|
125
|
+
expect.anything(),
|
|
126
|
+
expect.stringContaining('begin_checkout'),
|
|
127
|
+
expect.objectContaining({
|
|
128
|
+
coupon: 'SUMMER_123',
|
|
129
|
+
currency: 'USD',
|
|
130
|
+
items: [{ currency: 'USD', item_id: '12345', item_name: 'Monopoly: 3rd Edition' }],
|
|
131
|
+
value: 10,
|
|
132
|
+
send_to: settings.measurementID
|
|
133
|
+
})
|
|
134
|
+
)
|
|
135
|
+
})
|
|
136
|
+
test('GA4 beginCheckout Event when send to is undefined', async () => {
|
|
68
137
|
const context = new Context({
|
|
69
138
|
event: 'Begin Checkout',
|
|
70
139
|
type: 'track',
|
|
@@ -91,7 +160,8 @@ describe('GoogleAnalytics4Web.beginCheckout', () => {
|
|
|
91
160
|
coupon: 'SUMMER_123',
|
|
92
161
|
currency: 'USD',
|
|
93
162
|
items: [{ currency: 'USD', item_id: '12345', item_name: 'Monopoly: 3rd Edition' }],
|
|
94
|
-
value: 10
|
|
163
|
+
value: 10,
|
|
164
|
+
send_to: 'default'
|
|
95
165
|
})
|
|
96
166
|
)
|
|
97
167
|
})
|
|
@@ -12,6 +12,9 @@ const subscriptions: Subscription[] = [
|
|
|
12
12
|
name: {
|
|
13
13
|
'@path': '$.event'
|
|
14
14
|
},
|
|
15
|
+
send_to: {
|
|
16
|
+
'@path': '$.properties.send_to'
|
|
17
|
+
},
|
|
15
18
|
params: {
|
|
16
19
|
'@path': '$.properties.params'
|
|
17
20
|
}
|
|
@@ -42,7 +45,34 @@ describe('GoogleAnalytics4Web.customEvent', () => {
|
|
|
42
45
|
await trackEventPlugin.load(Context.system(), {} as Analytics)
|
|
43
46
|
})
|
|
44
47
|
|
|
45
|
-
test('GA4 customEvent Event', async () => {
|
|
48
|
+
test('GA4 customEvent Event when send_to is false', async () => {
|
|
49
|
+
const context = new Context({
|
|
50
|
+
event: 'Custom Event',
|
|
51
|
+
type: 'track',
|
|
52
|
+
properties: {
|
|
53
|
+
send_to: false,
|
|
54
|
+
params: [
|
|
55
|
+
{
|
|
56
|
+
paramOne: 'test123',
|
|
57
|
+
paramTwo: 'test123',
|
|
58
|
+
paramThree: 123
|
|
59
|
+
}
|
|
60
|
+
]
|
|
61
|
+
}
|
|
62
|
+
})
|
|
63
|
+
await customEvent.track?.(context)
|
|
64
|
+
|
|
65
|
+
expect(mockGA4).toHaveBeenCalledWith(
|
|
66
|
+
expect.anything(),
|
|
67
|
+
expect.stringContaining('Custom_Event'),
|
|
68
|
+
expect.objectContaining({
|
|
69
|
+
send_to: 'default',
|
|
70
|
+
...[{ paramOne: 'test123', paramThree: 123, paramTwo: 'test123' }]
|
|
71
|
+
})
|
|
72
|
+
)
|
|
73
|
+
})
|
|
74
|
+
|
|
75
|
+
test('GA4 customEvent Event when send_to is undefined', async () => {
|
|
46
76
|
const context = new Context({
|
|
47
77
|
event: 'Custom Event',
|
|
48
78
|
type: 'track',
|
|
@@ -61,7 +91,37 @@ describe('GoogleAnalytics4Web.customEvent', () => {
|
|
|
61
91
|
expect(mockGA4).toHaveBeenCalledWith(
|
|
62
92
|
expect.anything(),
|
|
63
93
|
expect.stringContaining('Custom_Event'),
|
|
64
|
-
expect.objectContaining(
|
|
94
|
+
expect.objectContaining({
|
|
95
|
+
send_to: 'default',
|
|
96
|
+
...[{ paramOne: 'test123', paramThree: 123, paramTwo: 'test123' }]
|
|
97
|
+
})
|
|
98
|
+
)
|
|
99
|
+
})
|
|
100
|
+
|
|
101
|
+
test('GA4 customEvent Event when send_to is true', async () => {
|
|
102
|
+
const context = new Context({
|
|
103
|
+
event: 'Custom Event',
|
|
104
|
+
type: 'track',
|
|
105
|
+
properties: {
|
|
106
|
+
params: [
|
|
107
|
+
{
|
|
108
|
+
paramOne: 'test123',
|
|
109
|
+
paramTwo: 'test123',
|
|
110
|
+
paramThree: 123
|
|
111
|
+
}
|
|
112
|
+
],
|
|
113
|
+
send_to: true
|
|
114
|
+
}
|
|
115
|
+
})
|
|
116
|
+
await customEvent.track?.(context)
|
|
117
|
+
|
|
118
|
+
expect(mockGA4).toHaveBeenCalledWith(
|
|
119
|
+
expect.anything(),
|
|
120
|
+
expect.stringContaining('Custom_Event'),
|
|
121
|
+
expect.objectContaining({
|
|
122
|
+
send_to: settings.measurementID,
|
|
123
|
+
...[{ paramOne: 'test123', paramThree: 123, paramTwo: 'test123' }]
|
|
124
|
+
})
|
|
65
125
|
)
|
|
66
126
|
})
|
|
67
127
|
})
|
|
@@ -14,6 +14,9 @@ const subscriptions: Subscription[] = [
|
|
|
14
14
|
},
|
|
15
15
|
value: {
|
|
16
16
|
'@path': '$.properties.value'
|
|
17
|
+
},
|
|
18
|
+
send_to: {
|
|
19
|
+
'@path': '$.properties.send_to'
|
|
17
20
|
}
|
|
18
21
|
}
|
|
19
22
|
}
|
|
@@ -42,13 +45,36 @@ describe('GoogleAnalytics4Web.generateLead', () => {
|
|
|
42
45
|
await trackEventPlugin.load(Context.system(), {} as Analytics)
|
|
43
46
|
})
|
|
44
47
|
|
|
45
|
-
test('GA4 generateLead Event', async () => {
|
|
48
|
+
test('GA4 generateLead Event when send to is false', async () => {
|
|
46
49
|
const context = new Context({
|
|
47
50
|
event: 'Generate Lead',
|
|
48
51
|
type: 'track',
|
|
49
52
|
properties: {
|
|
50
53
|
currency: 'USD',
|
|
51
|
-
value: 10
|
|
54
|
+
value: 10,
|
|
55
|
+
send_to: false
|
|
56
|
+
}
|
|
57
|
+
})
|
|
58
|
+
await generateLeadEvent.track?.(context)
|
|
59
|
+
|
|
60
|
+
expect(mockGA4).toHaveBeenCalledWith(
|
|
61
|
+
expect.anything(),
|
|
62
|
+
expect.stringContaining('generate_lead'),
|
|
63
|
+
expect.objectContaining({
|
|
64
|
+
currency: 'USD',
|
|
65
|
+
value: 10,
|
|
66
|
+
send_to: 'default'
|
|
67
|
+
})
|
|
68
|
+
)
|
|
69
|
+
})
|
|
70
|
+
test('GA4 generateLead Event when send to is true', async () => {
|
|
71
|
+
const context = new Context({
|
|
72
|
+
event: 'Generate Lead',
|
|
73
|
+
type: 'track',
|
|
74
|
+
properties: {
|
|
75
|
+
currency: 'USD',
|
|
76
|
+
value: 10,
|
|
77
|
+
send_to: true
|
|
52
78
|
}
|
|
53
79
|
})
|
|
54
80
|
await generateLeadEvent.track?.(context)
|
|
@@ -57,8 +83,30 @@ describe('GoogleAnalytics4Web.generateLead', () => {
|
|
|
57
83
|
expect.anything(),
|
|
58
84
|
expect.stringContaining('generate_lead'),
|
|
59
85
|
expect.objectContaining({
|
|
86
|
+
currency: 'USD',
|
|
87
|
+
value: 10,
|
|
88
|
+
send_to: settings.measurementID
|
|
89
|
+
})
|
|
90
|
+
)
|
|
91
|
+
})
|
|
92
|
+
test('GA4 generateLead Event when send to is undefined', async () => {
|
|
93
|
+
const context = new Context({
|
|
94
|
+
event: 'Generate Lead',
|
|
95
|
+
type: 'track',
|
|
96
|
+
properties: {
|
|
60
97
|
currency: 'USD',
|
|
61
98
|
value: 10
|
|
99
|
+
}
|
|
100
|
+
})
|
|
101
|
+
await generateLeadEvent.track?.(context)
|
|
102
|
+
|
|
103
|
+
expect(mockGA4).toHaveBeenCalledWith(
|
|
104
|
+
expect.anything(),
|
|
105
|
+
expect.stringContaining('generate_lead'),
|
|
106
|
+
expect.objectContaining({
|
|
107
|
+
currency: 'USD',
|
|
108
|
+
value: 10,
|
|
109
|
+
send_to: 'default'
|
|
62
110
|
})
|
|
63
111
|
)
|
|
64
112
|
})
|
|
@@ -11,6 +11,9 @@ const subscriptions: Subscription[] = [
|
|
|
11
11
|
mapping: {
|
|
12
12
|
method: {
|
|
13
13
|
'@path': '$.properties.method'
|
|
14
|
+
},
|
|
15
|
+
send_to: {
|
|
16
|
+
'@path': '$.properties.send_to'
|
|
14
17
|
}
|
|
15
18
|
}
|
|
16
19
|
}
|
|
@@ -39,12 +42,33 @@ describe('GoogleAnalytics4Web.login', () => {
|
|
|
39
42
|
await trackEventPlugin.load(Context.system(), {} as Analytics)
|
|
40
43
|
})
|
|
41
44
|
|
|
42
|
-
test('GA4 login Event', async () => {
|
|
45
|
+
test('GA4 login Event when send to is false', async () => {
|
|
43
46
|
const context = new Context({
|
|
44
47
|
event: 'Login',
|
|
45
48
|
type: 'track',
|
|
46
49
|
properties: {
|
|
47
|
-
method: 'Google'
|
|
50
|
+
method: 'Google',
|
|
51
|
+
send_to: false
|
|
52
|
+
}
|
|
53
|
+
})
|
|
54
|
+
await loginEvent.track?.(context)
|
|
55
|
+
|
|
56
|
+
expect(mockGA4).toHaveBeenCalledWith(
|
|
57
|
+
expect.anything(),
|
|
58
|
+
expect.stringContaining('login'),
|
|
59
|
+
expect.objectContaining({
|
|
60
|
+
method: 'Google',
|
|
61
|
+
send_to: 'default'
|
|
62
|
+
})
|
|
63
|
+
)
|
|
64
|
+
})
|
|
65
|
+
test('GA4 login Event when send to is true', async () => {
|
|
66
|
+
const context = new Context({
|
|
67
|
+
event: 'Login',
|
|
68
|
+
type: 'track',
|
|
69
|
+
properties: {
|
|
70
|
+
method: 'Google',
|
|
71
|
+
send_to: true
|
|
48
72
|
}
|
|
49
73
|
})
|
|
50
74
|
await loginEvent.track?.(context)
|
|
@@ -53,7 +77,28 @@ describe('GoogleAnalytics4Web.login', () => {
|
|
|
53
77
|
expect.anything(),
|
|
54
78
|
expect.stringContaining('login'),
|
|
55
79
|
expect.objectContaining({
|
|
80
|
+
method: 'Google',
|
|
81
|
+
send_to: settings.measurementID
|
|
82
|
+
})
|
|
83
|
+
)
|
|
84
|
+
})
|
|
85
|
+
|
|
86
|
+
test('GA4 login Event when send to is undefined', async () => {
|
|
87
|
+
const context = new Context({
|
|
88
|
+
event: 'Login',
|
|
89
|
+
type: 'track',
|
|
90
|
+
properties: {
|
|
56
91
|
method: 'Google'
|
|
92
|
+
}
|
|
93
|
+
})
|
|
94
|
+
await loginEvent.track?.(context)
|
|
95
|
+
|
|
96
|
+
expect(mockGA4).toHaveBeenCalledWith(
|
|
97
|
+
expect.anything(),
|
|
98
|
+
expect.stringContaining('login'),
|
|
99
|
+
expect.objectContaining({
|
|
100
|
+
method: 'Google',
|
|
101
|
+
send_to: 'default'
|
|
57
102
|
})
|
|
58
103
|
)
|
|
59
104
|
})
|
|
@@ -21,6 +21,9 @@ const subscriptions: Subscription[] = [
|
|
|
21
21
|
transaction_id: {
|
|
22
22
|
'@path': '$.properties.transaction_id'
|
|
23
23
|
},
|
|
24
|
+
send_to: {
|
|
25
|
+
'@path': '$.properties.send_to'
|
|
26
|
+
},
|
|
24
27
|
items: [
|
|
25
28
|
{
|
|
26
29
|
item_name: {
|
|
@@ -67,7 +70,7 @@ describe('GoogleAnalytics4Web.purchase', () => {
|
|
|
67
70
|
await trackEventPlugin.load(Context.system(), {} as Analytics)
|
|
68
71
|
})
|
|
69
72
|
|
|
70
|
-
test('GA4 purchase Event', async () => {
|
|
73
|
+
test('GA4 purchase Event when send to is false', async () => {
|
|
71
74
|
const context = new Context({
|
|
72
75
|
event: 'Purchase',
|
|
73
76
|
type: 'track',
|
|
@@ -75,6 +78,7 @@ describe('GoogleAnalytics4Web.purchase', () => {
|
|
|
75
78
|
currency: 'USD',
|
|
76
79
|
value: 10,
|
|
77
80
|
transaction_id: 12321,
|
|
81
|
+
send_to: false,
|
|
78
82
|
products: [
|
|
79
83
|
{
|
|
80
84
|
product_id: '12345',
|
|
@@ -93,7 +97,72 @@ describe('GoogleAnalytics4Web.purchase', () => {
|
|
|
93
97
|
currency: 'USD',
|
|
94
98
|
transaction_id: 12321,
|
|
95
99
|
items: [{ currency: 'USD', item_id: '12345', item_name: 'Monopoly: 3rd Edition' }],
|
|
96
|
-
value: 10
|
|
100
|
+
value: 10,
|
|
101
|
+
send_to: 'default'
|
|
102
|
+
})
|
|
103
|
+
)
|
|
104
|
+
})
|
|
105
|
+
test('GA4 purchase Event when send to is true', async () => {
|
|
106
|
+
const context = new Context({
|
|
107
|
+
event: 'Purchase',
|
|
108
|
+
type: 'track',
|
|
109
|
+
properties: {
|
|
110
|
+
currency: 'USD',
|
|
111
|
+
value: 10,
|
|
112
|
+
transaction_id: 12321,
|
|
113
|
+
send_to: true,
|
|
114
|
+
products: [
|
|
115
|
+
{
|
|
116
|
+
product_id: '12345',
|
|
117
|
+
name: 'Monopoly: 3rd Edition',
|
|
118
|
+
currency: 'USD'
|
|
119
|
+
}
|
|
120
|
+
]
|
|
121
|
+
}
|
|
122
|
+
})
|
|
123
|
+
await purchaseEvent.track?.(context)
|
|
124
|
+
|
|
125
|
+
expect(mockGA4).toHaveBeenCalledWith(
|
|
126
|
+
expect.anything(),
|
|
127
|
+
expect.stringContaining('purchase'),
|
|
128
|
+
expect.objectContaining({
|
|
129
|
+
currency: 'USD',
|
|
130
|
+
transaction_id: 12321,
|
|
131
|
+
items: [{ currency: 'USD', item_id: '12345', item_name: 'Monopoly: 3rd Edition' }],
|
|
132
|
+
value: 10,
|
|
133
|
+
send_to: settings.measurementID
|
|
134
|
+
})
|
|
135
|
+
)
|
|
136
|
+
})
|
|
137
|
+
|
|
138
|
+
test('GA4 purchase Event when send to is undefined', async () => {
|
|
139
|
+
const context = new Context({
|
|
140
|
+
event: 'Purchase',
|
|
141
|
+
type: 'track',
|
|
142
|
+
properties: {
|
|
143
|
+
currency: 'USD',
|
|
144
|
+
value: 10,
|
|
145
|
+
transaction_id: 12321,
|
|
146
|
+
products: [
|
|
147
|
+
{
|
|
148
|
+
product_id: '12345',
|
|
149
|
+
name: 'Monopoly: 3rd Edition',
|
|
150
|
+
currency: 'USD'
|
|
151
|
+
}
|
|
152
|
+
]
|
|
153
|
+
}
|
|
154
|
+
})
|
|
155
|
+
await purchaseEvent.track?.(context)
|
|
156
|
+
|
|
157
|
+
expect(mockGA4).toHaveBeenCalledWith(
|
|
158
|
+
expect.anything(),
|
|
159
|
+
expect.stringContaining('purchase'),
|
|
160
|
+
expect.objectContaining({
|
|
161
|
+
currency: 'USD',
|
|
162
|
+
transaction_id: 12321,
|
|
163
|
+
items: [{ currency: 'USD', item_id: '12345', item_name: 'Monopoly: 3rd Edition' }],
|
|
164
|
+
value: 10,
|
|
165
|
+
send_to: 'default'
|
|
97
166
|
})
|
|
98
167
|
)
|
|
99
168
|
})
|