@segment/analytics-browser-actions-google-analytics-4 1.33.0 → 1.36.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.
Files changed (188) hide show
  1. package/dist/cjs/addPaymentInfo/generated-types.d.ts +1 -0
  2. package/dist/cjs/addPaymentInfo/index.js +4 -2
  3. package/dist/cjs/addPaymentInfo/index.js.map +1 -1
  4. package/dist/cjs/addToCart/generated-types.d.ts +1 -0
  5. package/dist/cjs/addToCart/index.js +4 -2
  6. package/dist/cjs/addToCart/index.js.map +1 -1
  7. package/dist/cjs/addToWishlist/generated-types.d.ts +1 -0
  8. package/dist/cjs/addToWishlist/index.js +4 -2
  9. package/dist/cjs/addToWishlist/index.js.map +1 -1
  10. package/dist/cjs/beginCheckout/generated-types.d.ts +1 -0
  11. package/dist/cjs/beginCheckout/index.js +4 -2
  12. package/dist/cjs/beginCheckout/index.js.map +1 -1
  13. package/dist/cjs/customEvent/generated-types.d.ts +1 -0
  14. package/dist/cjs/customEvent/index.js +4 -2
  15. package/dist/cjs/customEvent/index.js.map +1 -1
  16. package/dist/cjs/ga4-properties.d.ts +1 -0
  17. package/dist/cjs/ga4-properties.js +7 -1
  18. package/dist/cjs/ga4-properties.js.map +1 -1
  19. package/dist/cjs/generateLead/generated-types.d.ts +1 -0
  20. package/dist/cjs/generateLead/index.js +4 -2
  21. package/dist/cjs/generateLead/index.js.map +1 -1
  22. package/dist/cjs/generated-types.d.ts +3 -1
  23. package/dist/cjs/index.js +39 -7
  24. package/dist/cjs/index.js.map +1 -1
  25. package/dist/cjs/login/generated-types.d.ts +1 -0
  26. package/dist/cjs/login/index.js +4 -2
  27. package/dist/cjs/login/index.js.map +1 -1
  28. package/dist/cjs/purchase/generated-types.d.ts +1 -0
  29. package/dist/cjs/purchase/index.js +4 -2
  30. package/dist/cjs/purchase/index.js.map +1 -1
  31. package/dist/cjs/refund/generated-types.d.ts +1 -0
  32. package/dist/cjs/refund/index.js +4 -2
  33. package/dist/cjs/refund/index.js.map +1 -1
  34. package/dist/cjs/removeFromCart/generated-types.d.ts +1 -0
  35. package/dist/cjs/removeFromCart/index.js +4 -2
  36. package/dist/cjs/removeFromCart/index.js.map +1 -1
  37. package/dist/cjs/search/generated-types.d.ts +1 -0
  38. package/dist/cjs/search/index.js +4 -2
  39. package/dist/cjs/search/index.js.map +1 -1
  40. package/dist/cjs/selectItem/generated-types.d.ts +1 -0
  41. package/dist/cjs/selectItem/index.js +4 -2
  42. package/dist/cjs/selectItem/index.js.map +1 -1
  43. package/dist/cjs/selectPromotion/generated-types.d.ts +1 -0
  44. package/dist/cjs/selectPromotion/index.js +4 -2
  45. package/dist/cjs/selectPromotion/index.js.map +1 -1
  46. package/dist/cjs/setConfigurationFields/generated-types.d.ts +2 -0
  47. package/dist/cjs/setConfigurationFields/index.js +47 -14
  48. package/dist/cjs/setConfigurationFields/index.js.map +1 -1
  49. package/dist/cjs/signUp/generated-types.d.ts +1 -0
  50. package/dist/cjs/signUp/index.js +4 -2
  51. package/dist/cjs/signUp/index.js.map +1 -1
  52. package/dist/cjs/viewCart/generated-types.d.ts +1 -0
  53. package/dist/cjs/viewCart/index.js +4 -2
  54. package/dist/cjs/viewCart/index.js.map +1 -1
  55. package/dist/cjs/viewItem/generated-types.d.ts +1 -0
  56. package/dist/cjs/viewItem/index.js +4 -2
  57. package/dist/cjs/viewItem/index.js.map +1 -1
  58. package/dist/cjs/viewItemList/generated-types.d.ts +1 -0
  59. package/dist/cjs/viewItemList/index.js +4 -2
  60. package/dist/cjs/viewItemList/index.js.map +1 -1
  61. package/dist/cjs/viewPromotion/generated-types.d.ts +1 -0
  62. package/dist/cjs/viewPromotion/index.js +4 -2
  63. package/dist/cjs/viewPromotion/index.js.map +1 -1
  64. package/dist/esm/addPaymentInfo/generated-types.d.ts +1 -0
  65. package/dist/esm/addPaymentInfo/index.js +5 -3
  66. package/dist/esm/addPaymentInfo/index.js.map +1 -1
  67. package/dist/esm/addToCart/generated-types.d.ts +1 -0
  68. package/dist/esm/addToCart/index.js +5 -3
  69. package/dist/esm/addToCart/index.js.map +1 -1
  70. package/dist/esm/addToWishlist/generated-types.d.ts +1 -0
  71. package/dist/esm/addToWishlist/index.js +5 -3
  72. package/dist/esm/addToWishlist/index.js.map +1 -1
  73. package/dist/esm/beginCheckout/generated-types.d.ts +1 -0
  74. package/dist/esm/beginCheckout/index.js +5 -3
  75. package/dist/esm/beginCheckout/index.js.map +1 -1
  76. package/dist/esm/customEvent/generated-types.d.ts +1 -0
  77. package/dist/esm/customEvent/index.js +5 -3
  78. package/dist/esm/customEvent/index.js.map +1 -1
  79. package/dist/esm/ga4-properties.d.ts +1 -0
  80. package/dist/esm/ga4-properties.js +6 -0
  81. package/dist/esm/ga4-properties.js.map +1 -1
  82. package/dist/esm/generateLead/generated-types.d.ts +1 -0
  83. package/dist/esm/generateLead/index.js +5 -3
  84. package/dist/esm/generateLead/index.js.map +1 -1
  85. package/dist/esm/generated-types.d.ts +3 -1
  86. package/dist/esm/index.js +39 -7
  87. package/dist/esm/index.js.map +1 -1
  88. package/dist/esm/login/generated-types.d.ts +1 -0
  89. package/dist/esm/login/index.js +5 -3
  90. package/dist/esm/login/index.js.map +1 -1
  91. package/dist/esm/purchase/generated-types.d.ts +1 -0
  92. package/dist/esm/purchase/index.js +5 -3
  93. package/dist/esm/purchase/index.js.map +1 -1
  94. package/dist/esm/refund/generated-types.d.ts +1 -0
  95. package/dist/esm/refund/index.js +5 -3
  96. package/dist/esm/refund/index.js.map +1 -1
  97. package/dist/esm/removeFromCart/generated-types.d.ts +1 -0
  98. package/dist/esm/removeFromCart/index.js +5 -3
  99. package/dist/esm/removeFromCart/index.js.map +1 -1
  100. package/dist/esm/search/generated-types.d.ts +1 -0
  101. package/dist/esm/search/index.js +5 -3
  102. package/dist/esm/search/index.js.map +1 -1
  103. package/dist/esm/selectItem/generated-types.d.ts +1 -0
  104. package/dist/esm/selectItem/index.js +5 -3
  105. package/dist/esm/selectItem/index.js.map +1 -1
  106. package/dist/esm/selectPromotion/generated-types.d.ts +1 -0
  107. package/dist/esm/selectPromotion/index.js +5 -3
  108. package/dist/esm/selectPromotion/index.js.map +1 -1
  109. package/dist/esm/setConfigurationFields/generated-types.d.ts +2 -0
  110. package/dist/esm/setConfigurationFields/index.js +47 -14
  111. package/dist/esm/setConfigurationFields/index.js.map +1 -1
  112. package/dist/esm/signUp/generated-types.d.ts +1 -0
  113. package/dist/esm/signUp/index.js +5 -3
  114. package/dist/esm/signUp/index.js.map +1 -1
  115. package/dist/esm/viewCart/generated-types.d.ts +1 -0
  116. package/dist/esm/viewCart/index.js +5 -3
  117. package/dist/esm/viewCart/index.js.map +1 -1
  118. package/dist/esm/viewItem/generated-types.d.ts +1 -0
  119. package/dist/esm/viewItem/index.js +5 -3
  120. package/dist/esm/viewItem/index.js.map +1 -1
  121. package/dist/esm/viewItemList/generated-types.d.ts +1 -0
  122. package/dist/esm/viewItemList/index.js +5 -3
  123. package/dist/esm/viewItemList/index.js.map +1 -1
  124. package/dist/esm/viewPromotion/generated-types.d.ts +1 -0
  125. package/dist/esm/viewPromotion/index.js +5 -3
  126. package/dist/esm/viewPromotion/index.js.map +1 -1
  127. package/dist/tsconfig.tsbuildinfo +1 -1
  128. package/package.json +4 -4
  129. package/src/__tests__/addPaymentInfo.test.ts +74 -2
  130. package/src/__tests__/addToCart.test.ts +67 -2
  131. package/src/__tests__/addToWishlist.test.ts +68 -2
  132. package/src/__tests__/beginCheckout.test.ts +72 -2
  133. package/src/__tests__/customEvent.test.ts +62 -2
  134. package/src/__tests__/generateLead.test.ts +50 -2
  135. package/src/__tests__/login.test.ts +47 -2
  136. package/src/__tests__/purchase.test.ts +71 -2
  137. package/src/__tests__/refund.test.ts +70 -2
  138. package/src/__tests__/removeFromCart.test.ts +69 -2
  139. package/src/__tests__/search.test.ts +48 -2
  140. package/src/__tests__/selectItem.test.ts +69 -2
  141. package/src/__tests__/selectPromotion.test.ts +81 -2
  142. package/src/__tests__/setConfigurationFields.test.ts +618 -0
  143. package/src/__tests__/signUp.test.ts +42 -2
  144. package/src/__tests__/viewCart.test.ts +69 -2
  145. package/src/__tests__/viewItem.test.ts +68 -2
  146. package/src/__tests__/viewItemList.test.ts +70 -2
  147. package/src/__tests__/viewPromotion.test.ts +80 -2
  148. package/src/addPaymentInfo/generated-types.ts +4 -0
  149. package/src/addPaymentInfo/index.ts +6 -3
  150. package/src/addToCart/generated-types.ts +4 -0
  151. package/src/addToCart/index.ts +5 -3
  152. package/src/addToWishlist/generated-types.ts +4 -0
  153. package/src/addToWishlist/index.ts +5 -3
  154. package/src/beginCheckout/generated-types.ts +4 -0
  155. package/src/beginCheckout/index.ts +14 -3
  156. package/src/customEvent/generated-types.ts +4 -0
  157. package/src/customEvent/index.ts +5 -3
  158. package/src/ga4-properties.ts +7 -0
  159. package/src/generateLead/generated-types.ts +4 -0
  160. package/src/generateLead/index.ts +5 -3
  161. package/src/generated-types.ts +10 -2
  162. package/src/index.ts +47 -7
  163. package/src/login/generated-types.ts +4 -0
  164. package/src/login/index.ts +5 -3
  165. package/src/purchase/generated-types.ts +4 -0
  166. package/src/purchase/index.ts +6 -3
  167. package/src/refund/generated-types.ts +4 -0
  168. package/src/refund/index.ts +6 -3
  169. package/src/removeFromCart/generated-types.ts +4 -0
  170. package/src/removeFromCart/index.ts +5 -3
  171. package/src/search/generated-types.ts +4 -0
  172. package/src/search/index.ts +5 -3
  173. package/src/selectItem/generated-types.ts +4 -0
  174. package/src/selectItem/index.ts +6 -3
  175. package/src/selectPromotion/generated-types.ts +4 -0
  176. package/src/selectPromotion/index.ts +6 -3
  177. package/src/setConfigurationFields/generated-types.ts +8 -0
  178. package/src/setConfigurationFields/index.ts +57 -14
  179. package/src/signUp/generated-types.ts +4 -0
  180. package/src/signUp/index.ts +5 -3
  181. package/src/viewCart/generated-types.ts +4 -0
  182. package/src/viewCart/index.ts +5 -3
  183. package/src/viewItem/generated-types.ts +4 -0
  184. package/src/viewItem/index.ts +5 -3
  185. package/src/viewItemList/generated-types.ts +4 -0
  186. package/src/viewItemList/index.ts +13 -3
  187. package/src/viewPromotion/generated-types.ts +4 -0
  188. package/src/viewPromotion/index.ts +6 -3
@@ -0,0 +1,618 @@
1
+ import googleAnalytics4Web, { destination } from '../index'
2
+ import { Analytics, Context } from '@segment/analytics-next'
3
+ import { Subscription } from '@segment/browser-destination-runtime/types'
4
+ import type { Settings } from '../generated-types'
5
+
6
+ let mockGtag: GA
7
+ let setConfigurationEvent: any
8
+ const subscriptions: Subscription[] = [
9
+ {
10
+ partnerAction: 'setConfigurationFields',
11
+ name: 'Set Configuration Fields',
12
+ enabled: true,
13
+ subscribe: 'type = "page"',
14
+ mapping: {
15
+ ads_storage_consent_state: {
16
+ '@path': '$.properties.ads_storage_consent_state'
17
+ },
18
+ analytics_storage_consent_state: {
19
+ '@path': '$.properties.analytics_storage_consent_state'
20
+ },
21
+ screen_resolution: {
22
+ '@path': '$.properties.screen_resolution'
23
+ },
24
+ user_id: {
25
+ '@path': '$.properties.user_id'
26
+ },
27
+ page_title: {
28
+ '@path': '$.properties.page_title'
29
+ },
30
+ page_referrer: {
31
+ '@path': '$.properties.page_referrer'
32
+ },
33
+ language: {
34
+ '@path': '$.properties.language'
35
+ },
36
+ content_group: {
37
+ '@path': '$.properties.content_group'
38
+ },
39
+ campaign_content: {
40
+ '@path': '$.properties.campaign_content'
41
+ },
42
+ campaign_id: {
43
+ '@path': '$.properties.campaign_id'
44
+ },
45
+ campaign_medium: {
46
+ '@path': '$.properties.campaign_medium'
47
+ },
48
+ campaign_name: {
49
+ '@path': '$.properties.campaign_name'
50
+ },
51
+ campaign_source: {
52
+ '@path': '$.properties.campaign_source'
53
+ },
54
+ campaign_term: {
55
+ '@path': '$.properties.campaign_term'
56
+ },
57
+ ad_user_data_consent_state: {
58
+ '@path': '$.properties.ad_user_data_consent_state'
59
+ },
60
+ ad_personalization_consent_state: {
61
+ '@path': '$.properties.ad_personalization_consent_state'
62
+ }
63
+ }
64
+ }
65
+ ]
66
+
67
+ describe('Set Configuration Fields action', () => {
68
+ const defaultSettings: Settings = {
69
+ enableConsentMode: false,
70
+ measurementID: 'G-XXXXXXXXXX',
71
+ allowAdPersonalizationSignals: false,
72
+ allowGoogleSignals: false,
73
+ cookieDomain: 'auto',
74
+ cookieExpirationInSeconds: 63072000,
75
+ cookieUpdate: true,
76
+ pageView: true
77
+ }
78
+ beforeEach(async () => {
79
+ jest.restoreAllMocks()
80
+
81
+ const [setConfigurationEventPlugin] = await googleAnalytics4Web({
82
+ ...defaultSettings,
83
+ subscriptions
84
+ })
85
+ setConfigurationEvent = setConfigurationEventPlugin
86
+
87
+ jest.spyOn(destination, 'initialize').mockImplementation(() => {
88
+ mockGtag = jest.fn()
89
+ return Promise.resolve(mockGtag)
90
+ })
91
+ await setConfigurationEventPlugin.load(Context.system(), {} as Analytics)
92
+ })
93
+
94
+ it('should configure consent when consent mode is enabled', async () => {
95
+ defaultSettings.enableConsentMode = true
96
+
97
+ const [setConfigurationEventPlugin] = await googleAnalytics4Web({
98
+ ...defaultSettings,
99
+ subscriptions
100
+ })
101
+ setConfigurationEvent = setConfigurationEventPlugin
102
+ await setConfigurationEventPlugin.load(Context.system(), {} as Analytics)
103
+
104
+ const context = new Context({
105
+ event: 'setConfigurationFields',
106
+ type: 'page',
107
+ properties: {
108
+ ads_storage_consent_state: 'granted',
109
+ analytics_storage_consent_state: 'denied'
110
+ }
111
+ })
112
+
113
+ setConfigurationEvent.page?.(context)
114
+
115
+ expect(mockGtag).toHaveBeenCalledWith('consent', 'update', {
116
+ ad_storage: 'granted',
117
+ analytics_storage: 'denied'
118
+ })
119
+ expect(mockGtag).toHaveBeenCalledWith('config', 'G-XXXXXXXXXX', {
120
+ allow_ad_personalization_signals: false,
121
+ allow_google_signals: false
122
+ })
123
+ })
124
+ it('should configure cookie expiry time other then default value', async () => {
125
+ const settings = {
126
+ ...defaultSettings,
127
+ cookieExpirationInSeconds: 500
128
+ }
129
+ const [setConfigurationEventPlugin] = await googleAnalytics4Web({
130
+ ...settings,
131
+ subscriptions
132
+ })
133
+ setConfigurationEvent = setConfigurationEventPlugin
134
+ await setConfigurationEventPlugin.load(Context.system(), {} as Analytics)
135
+
136
+ const context = new Context({
137
+ event: 'setConfigurationFields',
138
+ type: 'page',
139
+ properties: {}
140
+ })
141
+
142
+ setConfigurationEvent.page?.(context)
143
+
144
+ expect(mockGtag).toHaveBeenCalledWith('config', 'G-XXXXXXXXXX', {
145
+ allow_ad_personalization_signals: false,
146
+ allow_google_signals: false,
147
+ cookie_expires: 500
148
+ })
149
+ })
150
+ it('should configure cookie domain other then default value', async () => {
151
+ const settings = {
152
+ ...defaultSettings,
153
+ cookieDomain: 'example.com'
154
+ }
155
+
156
+ const [setConfigurationEventPlugin] = await googleAnalytics4Web({
157
+ ...settings,
158
+ subscriptions
159
+ })
160
+ setConfigurationEvent = setConfigurationEventPlugin
161
+ await setConfigurationEventPlugin.load(Context.system(), {} as Analytics)
162
+
163
+ const context = new Context({
164
+ event: 'setConfigurationFields',
165
+ type: 'page',
166
+ properties: {}
167
+ })
168
+
169
+ setConfigurationEvent.page?.(context)
170
+
171
+ expect(mockGtag).toHaveBeenCalledWith('config', 'G-XXXXXXXXXX', {
172
+ allow_ad_personalization_signals: false,
173
+ allow_google_signals: false,
174
+ cookie_domain: 'example.com'
175
+ })
176
+ })
177
+ it('should configure cookie prefix other then default value', async () => {
178
+ const settings = {
179
+ ...defaultSettings,
180
+ cookiePrefix: 'stage'
181
+ }
182
+ const [setConfigurationEventPlugin] = await googleAnalytics4Web({
183
+ ...settings,
184
+ subscriptions
185
+ })
186
+ setConfigurationEvent = setConfigurationEventPlugin
187
+ await setConfigurationEventPlugin.load(Context.system(), {} as Analytics)
188
+
189
+ const context = new Context({
190
+ event: 'setConfigurationFields',
191
+ type: 'page',
192
+ properties: {}
193
+ })
194
+
195
+ setConfigurationEvent.page?.(context)
196
+
197
+ expect(mockGtag).toHaveBeenCalledWith('config', 'G-XXXXXXXXXX', {
198
+ allow_ad_personalization_signals: false,
199
+ allow_google_signals: false,
200
+ cookie_prefix: 'stage'
201
+ })
202
+ })
203
+ it('should configure cookie path other then default value', async () => {
204
+ const settings = {
205
+ ...defaultSettings,
206
+ cookiePath: '/home'
207
+ }
208
+
209
+ const [setConfigurationEventPlugin] = await googleAnalytics4Web({
210
+ ...settings,
211
+ subscriptions
212
+ })
213
+ setConfigurationEvent = setConfigurationEventPlugin
214
+ await setConfigurationEventPlugin.load(Context.system(), {} as Analytics)
215
+
216
+ const context = new Context({
217
+ event: 'setConfigurationFields',
218
+ type: 'page',
219
+ properties: {}
220
+ })
221
+
222
+ setConfigurationEvent.page?.(context)
223
+
224
+ expect(mockGtag).toHaveBeenCalledWith('config', 'G-XXXXXXXXXX', {
225
+ allow_ad_personalization_signals: false,
226
+ allow_google_signals: false,
227
+ cookie_path: '/home'
228
+ })
229
+ })
230
+ it('should configure cookie update other then default value', async () => {
231
+ const settings = {
232
+ ...defaultSettings,
233
+ cookieUpdate: false
234
+ }
235
+ const [setConfigurationEventPlugin] = await googleAnalytics4Web({
236
+ ...settings,
237
+ subscriptions
238
+ })
239
+ setConfigurationEvent = setConfigurationEventPlugin
240
+ await setConfigurationEventPlugin.load(Context.system(), {} as Analytics)
241
+
242
+ const context = new Context({
243
+ event: 'setConfigurationFields',
244
+ type: 'page',
245
+ properties: {}
246
+ })
247
+
248
+ setConfigurationEvent.page?.(context)
249
+
250
+ expect(mockGtag).toHaveBeenCalledWith('config', 'G-XXXXXXXXXX', {
251
+ allow_ad_personalization_signals: false,
252
+ allow_google_signals: false,
253
+ cookie_update: false
254
+ })
255
+ })
256
+ it('should not configure consent when consent mode is disabled', async () => {
257
+ const settings = {
258
+ ...defaultSettings,
259
+ enableConsentMode: false
260
+ }
261
+ const [setConfigurationEventPlugin] = await googleAnalytics4Web({
262
+ ...settings,
263
+ subscriptions
264
+ })
265
+ setConfigurationEvent = setConfigurationEventPlugin
266
+ await setConfigurationEventPlugin.load(Context.system(), {} as Analytics)
267
+
268
+ const context = new Context({
269
+ event: 'setConfigurationFields',
270
+ type: 'page',
271
+ properties: {}
272
+ })
273
+
274
+ setConfigurationEvent.page?.(context)
275
+ expect(mockGtag).toHaveBeenCalledWith('config', 'G-XXXXXXXXXX', {
276
+ allow_ad_personalization_signals: false,
277
+ allow_google_signals: false
278
+ })
279
+ })
280
+ it('should update config if payload has screen resolution', () => {
281
+ const context = new Context({
282
+ event: 'setConfigurationFields',
283
+ type: 'page',
284
+ properties: {
285
+ screen_resolution: '800*600'
286
+ }
287
+ })
288
+
289
+ setConfigurationEvent.page?.(context)
290
+ expect(mockGtag).toHaveBeenCalledWith('config', 'G-XXXXXXXXXX', {
291
+ allow_ad_personalization_signals: false,
292
+ allow_google_signals: false,
293
+ screen_resolution: '800*600'
294
+ })
295
+ })
296
+ it('should update config if payload has user_id', () => {
297
+ const context = new Context({
298
+ event: 'setConfigurationFields',
299
+ type: 'page',
300
+ properties: {
301
+ user_id: 'segment-123'
302
+ }
303
+ })
304
+
305
+ setConfigurationEvent.page?.(context)
306
+ expect(mockGtag).toHaveBeenCalledWith('config', 'G-XXXXXXXXXX', {
307
+ allow_ad_personalization_signals: false,
308
+ allow_google_signals: false,
309
+ user_id: 'segment-123'
310
+ })
311
+ })
312
+ it('should update config if payload has page_title', () => {
313
+ const context = new Context({
314
+ event: 'setConfigurationFields',
315
+ type: 'page',
316
+ properties: {
317
+ page_title: 'User Registration Page'
318
+ }
319
+ })
320
+
321
+ setConfigurationEvent.page?.(context)
322
+ expect(mockGtag).toHaveBeenCalledWith('config', 'G-XXXXXXXXXX', {
323
+ allow_ad_personalization_signals: false,
324
+ allow_google_signals: false,
325
+ page_title: 'User Registration Page'
326
+ })
327
+ })
328
+ it('should update config if payload has language', () => {
329
+ const context = new Context({
330
+ event: 'setConfigurationFields',
331
+ type: 'page',
332
+ properties: {
333
+ language: 'EN'
334
+ }
335
+ })
336
+
337
+ setConfigurationEvent.page?.(context)
338
+ expect(mockGtag).toHaveBeenCalledWith('config', 'G-XXXXXXXXXX', {
339
+ allow_ad_personalization_signals: false,
340
+ allow_google_signals: false,
341
+ language: 'EN'
342
+ })
343
+ })
344
+ it('should update config if payload has content_group', () => {
345
+ const context = new Context({
346
+ event: 'setConfigurationFields',
347
+ type: 'page',
348
+ properties: {
349
+ content_group: '/home/login'
350
+ }
351
+ })
352
+
353
+ setConfigurationEvent.page?.(context)
354
+ expect(mockGtag).toHaveBeenCalledWith('config', 'G-XXXXXXXXXX', {
355
+ allow_ad_personalization_signals: false,
356
+ allow_google_signals: false,
357
+ content_group: '/home/login'
358
+ })
359
+ })
360
+ it('should update config if payload has campaign_term', () => {
361
+ const context = new Context({
362
+ event: 'setConfigurationFields',
363
+ type: 'page',
364
+ properties: {
365
+ campaign_term: 'running+shoes'
366
+ }
367
+ })
368
+
369
+ setConfigurationEvent.page?.(context)
370
+ expect(mockGtag).toHaveBeenCalledWith('config', 'G-XXXXXXXXXX', {
371
+ allow_ad_personalization_signals: false,
372
+ allow_google_signals: false,
373
+ campaign_term: 'running+shoes'
374
+ })
375
+ })
376
+ it('should update config if payload has campaign_source', () => {
377
+ const context = new Context({
378
+ event: 'setConfigurationFields',
379
+ type: 'page',
380
+ properties: {
381
+ campaign_source: 'google'
382
+ }
383
+ })
384
+
385
+ setConfigurationEvent.page?.(context)
386
+ expect(mockGtag).toHaveBeenCalledWith('config', 'G-XXXXXXXXXX', {
387
+ allow_ad_personalization_signals: false,
388
+ allow_google_signals: false,
389
+ campaign_source: 'google'
390
+ })
391
+ })
392
+ it('should update config if payload has campaign_name', () => {
393
+ const context = new Context({
394
+ event: 'setConfigurationFields',
395
+ type: 'page',
396
+ properties: {
397
+ campaign_name: 'spring_sale'
398
+ }
399
+ })
400
+
401
+ setConfigurationEvent.page?.(context)
402
+ expect(mockGtag).toHaveBeenCalledWith('config', 'G-XXXXXXXXXX', {
403
+ allow_ad_personalization_signals: false,
404
+ allow_google_signals: false,
405
+ campaign_name: 'spring_sale'
406
+ })
407
+ })
408
+ it('should update config if payload has campaign_medium', () => {
409
+ const context = new Context({
410
+ event: 'setConfigurationFields',
411
+ type: 'page',
412
+ properties: {
413
+ campaign_medium: 'cpc'
414
+ }
415
+ })
416
+
417
+ setConfigurationEvent.page?.(context)
418
+ expect(mockGtag).toHaveBeenCalledWith('config', 'G-XXXXXXXXXX', {
419
+ allow_ad_personalization_signals: false,
420
+ allow_google_signals: false,
421
+ campaign_medium: 'cpc'
422
+ })
423
+ })
424
+ it('should update config if payload has campaign_id', () => {
425
+ const context = new Context({
426
+ event: 'setConfigurationFields',
427
+ type: 'page',
428
+ properties: {
429
+ campaign_id: 'abc.123'
430
+ }
431
+ })
432
+
433
+ setConfigurationEvent.page?.(context)
434
+ expect(mockGtag).toHaveBeenCalledWith('config', 'G-XXXXXXXXXX', {
435
+ allow_ad_personalization_signals: false,
436
+ allow_google_signals: false,
437
+ campaign_id: 'abc.123'
438
+ })
439
+ })
440
+ it('should update config if payload has campaign_content', () => {
441
+ const context = new Context({
442
+ event: 'setConfigurationFields',
443
+ type: 'page',
444
+ properties: {
445
+ campaign_content: 'logolink'
446
+ }
447
+ })
448
+
449
+ setConfigurationEvent.page?.(context)
450
+ expect(mockGtag).toHaveBeenCalledWith('config', 'G-XXXXXXXXXX', {
451
+ allow_ad_personalization_signals: false,
452
+ allow_google_signals: false,
453
+ campaign_content: 'logolink'
454
+ })
455
+ })
456
+
457
+ it('should update config if payload has send_page_view is true', async () => {
458
+ const settings = {
459
+ ...defaultSettings,
460
+ pageView: true
461
+ }
462
+
463
+ const [setConfigurationEventPlugin] = await googleAnalytics4Web({
464
+ ...settings,
465
+ subscriptions
466
+ })
467
+ setConfigurationEvent = setConfigurationEventPlugin
468
+ await setConfigurationEventPlugin.load(Context.system(), {} as Analytics)
469
+
470
+ const context = new Context({
471
+ event: 'setConfigurationFields',
472
+ type: 'page',
473
+ properties: {}
474
+ })
475
+
476
+ setConfigurationEvent.page?.(context)
477
+ expect(mockGtag).toHaveBeenCalledWith('config', 'G-XXXXXXXXXX', {
478
+ allow_ad_personalization_signals: false,
479
+ allow_google_signals: false
480
+ })
481
+ })
482
+ it('should update config if payload has send_page_view is false', async () => {
483
+ const settings = {
484
+ ...defaultSettings,
485
+ pageView: false
486
+ }
487
+
488
+ const [setConfigurationEventPlugin] = await googleAnalytics4Web({
489
+ ...settings,
490
+ subscriptions
491
+ })
492
+ setConfigurationEvent = setConfigurationEventPlugin
493
+ await setConfigurationEventPlugin.load(Context.system(), {} as Analytics)
494
+
495
+ const context = new Context({
496
+ event: 'setConfigurationFields',
497
+ type: 'page',
498
+ properties: {}
499
+ })
500
+
501
+ setConfigurationEvent.page?.(context)
502
+ expect(mockGtag).toHaveBeenCalledWith('config', 'G-XXXXXXXXXX', {
503
+ allow_ad_personalization_signals: false,
504
+ allow_google_signals: false,
505
+ send_page_view: false
506
+ })
507
+ })
508
+ it('should update config if payload has send_page_view is undefined', async () => {
509
+ const settings = {
510
+ ...defaultSettings,
511
+ pageView: undefined
512
+ }
513
+
514
+ const [setConfigurationEventPlugin] = await googleAnalytics4Web({
515
+ ...settings,
516
+ subscriptions
517
+ })
518
+ setConfigurationEvent = setConfigurationEventPlugin
519
+ await setConfigurationEventPlugin.load(Context.system(), {} as Analytics)
520
+
521
+ const context = new Context({
522
+ event: 'setConfigurationFields',
523
+ type: 'page',
524
+ properties: {}
525
+ })
526
+
527
+ setConfigurationEvent.page?.(context)
528
+ expect(mockGtag).toHaveBeenCalledWith('config', 'G-XXXXXXXXXX', {
529
+ allow_ad_personalization_signals: false,
530
+ allow_google_signals: false,
531
+ send_page_view: true
532
+ })
533
+ })
534
+
535
+ it('should update consent if payload has ad_user_data_consent_state granted', () => {
536
+ const context = new Context({
537
+ event: 'setConfigurationFields',
538
+ type: 'page',
539
+ properties: {
540
+ ad_user_data_consent_state: 'granted'
541
+ }
542
+ })
543
+
544
+ setConfigurationEvent.page?.(context)
545
+ expect(mockGtag).toHaveBeenCalledWith('consent', 'update', {
546
+ ad_user_data: 'granted'
547
+ })
548
+ })
549
+
550
+ it('should update consent if payload has ad_user_data_consent_state denied', () => {
551
+ const context = new Context({
552
+ event: 'setConfigurationFields',
553
+ type: 'page',
554
+ properties: {
555
+ ad_user_data_consent_state: 'denied'
556
+ }
557
+ })
558
+
559
+ setConfigurationEvent.page?.(context)
560
+ expect(mockGtag).toHaveBeenCalledWith('consent', 'update', {
561
+ ad_user_data: 'denied'
562
+ })
563
+ })
564
+
565
+ it('should update consent if payload has ad_user_data_consent_state undefined', () => {
566
+ const context = new Context({
567
+ event: 'setConfigurationFields',
568
+ type: 'page',
569
+ properties: {
570
+ ad_user_data_consent_state: undefined
571
+ }
572
+ })
573
+
574
+ setConfigurationEvent.page?.(context)
575
+ expect(mockGtag).toHaveBeenCalledWith('consent', 'update', {})
576
+ })
577
+
578
+ it('should update consent if payload has ad_personalization_consent_state granted', () => {
579
+ const context = new Context({
580
+ event: 'setConfigurationFields',
581
+ type: 'page',
582
+ properties: {
583
+ ad_personalization_consent_state: 'granted'
584
+ }
585
+ })
586
+
587
+ setConfigurationEvent.page?.(context)
588
+ expect(mockGtag).toHaveBeenCalledWith('consent', 'update', {
589
+ ad_personalization: 'granted'
590
+ })
591
+ })
592
+ it('should update consent if payload has ad_personalization_consent_state denied', () => {
593
+ const context = new Context({
594
+ event: 'setConfigurationFields',
595
+ type: 'page',
596
+ properties: {
597
+ ad_personalization_consent_state: 'denied'
598
+ }
599
+ })
600
+
601
+ setConfigurationEvent.page?.(context)
602
+ expect(mockGtag).toHaveBeenCalledWith('consent', 'update', {
603
+ ad_personalization: 'denied'
604
+ })
605
+ })
606
+ it('should update consent if payload has ad_personalization_consent_state undefined', () => {
607
+ const context = new Context({
608
+ event: 'setConfigurationFields',
609
+ type: 'page',
610
+ properties: {
611
+ ad_personalization_consent_state: undefined
612
+ }
613
+ })
614
+
615
+ setConfigurationEvent.page?.(context)
616
+ expect(mockGtag).toHaveBeenCalledWith('consent', 'update', {})
617
+ })
618
+ })
@@ -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,7 +42,44 @@ describe('GoogleAnalytics4Web.signUp', () => {
39
42
  await trackEventPlugin.load(Context.system(), {} as Analytics)
40
43
  })
41
44
 
42
- test('GA4 signUp Event', async () => {
45
+ test('GA4 signUp Event when send to is false', async () => {
46
+ const context = new Context({
47
+ event: 'signUp',
48
+ type: 'track',
49
+ properties: {
50
+ method: 'Google',
51
+ send_to: false
52
+ }
53
+ })
54
+
55
+ await signUpEvent.track?.(context)
56
+
57
+ expect(mockGA4).toHaveBeenCalledWith(
58
+ expect.anything(),
59
+ expect.stringContaining('sign_up'),
60
+ expect.objectContaining({ method: 'Google', send_to: 'default' })
61
+ )
62
+ })
63
+ test('GA4 signUp Event when send to is true', async () => {
64
+ const context = new Context({
65
+ event: 'signUp',
66
+ type: 'track',
67
+ properties: {
68
+ method: 'Google',
69
+ send_to: true
70
+ }
71
+ })
72
+
73
+ await signUpEvent.track?.(context)
74
+
75
+ expect(mockGA4).toHaveBeenCalledWith(
76
+ expect.anything(),
77
+ expect.stringContaining('sign_up'),
78
+ expect.objectContaining({ method: 'Google', send_to: settings.measurementID })
79
+ )
80
+ })
81
+
82
+ test('GA4 signUp Event when send to is undefined', async () => {
43
83
  const context = new Context({
44
84
  event: 'signUp',
45
85
  type: 'track',
@@ -53,7 +93,7 @@ describe('GoogleAnalytics4Web.signUp', () => {
53
93
  expect(mockGA4).toHaveBeenCalledWith(
54
94
  expect.anything(),
55
95
  expect.stringContaining('sign_up'),
56
- expect.objectContaining({ method: 'Google' })
96
+ expect.objectContaining({ method: 'Google', send_to: 'default' })
57
97
  )
58
98
  })
59
99
  })