@segment/analytics-browser-actions-google-analytics-4 1.13.0 → 1.15.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 (35) hide show
  1. package/dist/cjs/index.js.map +1 -1
  2. package/dist/cjs/setConfigurationFields/index.js +3 -0
  3. package/dist/cjs/setConfigurationFields/index.js.map +1 -1
  4. package/dist/esm/index.js.map +1 -1
  5. package/dist/esm/setConfigurationFields/index.js +3 -0
  6. package/dist/esm/setConfigurationFields/index.js.map +1 -1
  7. package/dist/tsconfig.tsbuildinfo +1 -1
  8. package/package.json +2 -2
  9. package/src/__tests__/addPaymentInfo.test.ts +4 -7
  10. package/src/__tests__/addToCart.test.ts +4 -7
  11. package/src/__tests__/addToWishlist.test.ts +4 -7
  12. package/src/__tests__/beginCheckout.test.ts +4 -7
  13. package/src/__tests__/customEvent.test.ts +3 -6
  14. package/src/__tests__/generateLead.test.ts +4 -7
  15. package/src/__tests__/login.test.ts +3 -6
  16. package/src/__tests__/purchase.test.ts +4 -7
  17. package/src/__tests__/refund.test.ts +4 -7
  18. package/src/__tests__/removeFromCart.test.ts +4 -7
  19. package/src/__tests__/search.test.ts +4 -7
  20. package/src/__tests__/selectItem.test.ts +4 -7
  21. package/src/__tests__/selectPromotion.test.ts +4 -7
  22. package/src/__tests__/signUp.test.ts +4 -7
  23. package/src/__tests__/viewCart.test.ts +4 -7
  24. package/src/__tests__/viewItem.test.ts +4 -7
  25. package/src/__tests__/viewItemList.test.ts +4 -7
  26. package/src/__tests__/viewPromotion.test.ts +4 -7
  27. package/src/index.ts +4 -2
  28. package/src/setConfigurationFields/index.ts +7 -2
  29. package/dist/cjs/types.d.ts +0 -3
  30. package/dist/cjs/types.js +0 -3
  31. package/dist/cjs/types.js.map +0 -1
  32. package/dist/esm/types.d.ts +0 -3
  33. package/dist/esm/types.js +0 -2
  34. package/dist/esm/types.js.map +0 -1
  35. package/src/types.ts +0 -3
@@ -1,7 +1,6 @@
1
1
  import { Subscription } from '@segment/browser-destination-runtime/types'
2
2
  import { Analytics, Context } from '@segment/analytics-next'
3
3
  import googleAnalytics4Web, { destination } from '../index'
4
- import { GA } from '../types'
5
4
 
6
5
  const subscriptions: Subscription[] = [
7
6
  {
@@ -44,7 +43,7 @@ describe('GoogleAnalytics4Web.addToWishlist', () => {
44
43
  measurementID: 'test123'
45
44
  }
46
45
 
47
- let mockGA4: GA
46
+ let mockGA4: typeof gtag
48
47
  let addToWishlistEvent: any
49
48
  beforeEach(async () => {
50
49
  jest.restoreAllMocks()
@@ -56,10 +55,8 @@ describe('GoogleAnalytics4Web.addToWishlist', () => {
56
55
  addToWishlistEvent = trackEventPlugin
57
56
 
58
57
  jest.spyOn(destination, 'initialize').mockImplementation(() => {
59
- mockGA4 = {
60
- gtag: jest.fn()
61
- }
62
- return Promise.resolve(mockGA4.gtag)
58
+ mockGA4 = jest.fn()
59
+ return Promise.resolve(mockGA4)
63
60
  })
64
61
  await trackEventPlugin.load(Context.system(), {} as Analytics)
65
62
  })
@@ -82,7 +79,7 @@ describe('GoogleAnalytics4Web.addToWishlist', () => {
82
79
  })
83
80
  await addToWishlistEvent.track?.(context)
84
81
 
85
- expect(mockGA4.gtag).toHaveBeenCalledWith(
82
+ expect(mockGA4).toHaveBeenCalledWith(
86
83
  expect.anything(),
87
84
  expect.stringContaining('add_to_wishlist'),
88
85
  expect.objectContaining({
@@ -1,7 +1,6 @@
1
1
  import { Subscription } from '@segment/browser-destination-runtime/types'
2
2
  import { Analytics, Context } from '@segment/analytics-next'
3
3
  import googleAnalytics4Web, { destination } from '../index'
4
- import { GA } from '../types'
5
4
 
6
5
  const subscriptions: Subscription[] = [
7
6
  {
@@ -47,7 +46,7 @@ describe('GoogleAnalytics4Web.beginCheckout', () => {
47
46
  measurementID: 'test123'
48
47
  }
49
48
 
50
- let mockGA4: GA
49
+ let mockGA4: typeof gtag
51
50
  let beginCheckoutEvent: any
52
51
  beforeEach(async () => {
53
52
  jest.restoreAllMocks()
@@ -59,10 +58,8 @@ describe('GoogleAnalytics4Web.beginCheckout', () => {
59
58
  beginCheckoutEvent = trackEventPlugin
60
59
 
61
60
  jest.spyOn(destination, 'initialize').mockImplementation(() => {
62
- mockGA4 = {
63
- gtag: jest.fn()
64
- }
65
- return Promise.resolve(mockGA4.gtag)
61
+ mockGA4 = jest.fn()
62
+ return Promise.resolve(mockGA4)
66
63
  })
67
64
  await trackEventPlugin.load(Context.system(), {} as Analytics)
68
65
  })
@@ -87,7 +84,7 @@ describe('GoogleAnalytics4Web.beginCheckout', () => {
87
84
  })
88
85
  await beginCheckoutEvent.track?.(context)
89
86
 
90
- expect(mockGA4.gtag).toHaveBeenCalledWith(
87
+ expect(mockGA4).toHaveBeenCalledWith(
91
88
  expect.anything(),
92
89
  expect.stringContaining('begin_checkout'),
93
90
  expect.objectContaining({
@@ -1,7 +1,6 @@
1
1
  import { Subscription } from '@segment/browser-destination-runtime/types'
2
2
  import { Analytics, Context } from '@segment/analytics-next'
3
3
  import googleAnalytics4Web, { destination } from '../index'
4
- import { GA } from '../types'
5
4
 
6
5
  const subscriptions: Subscription[] = [
7
6
  {
@@ -37,10 +36,8 @@ describe('GoogleAnalytics4Web.customEvent', () => {
37
36
  customEvent = trackEventPlugin
38
37
 
39
38
  jest.spyOn(destination, 'initialize').mockImplementation(() => {
40
- mockGA4 = {
41
- gtag: jest.fn()
42
- }
43
- return Promise.resolve(mockGA4.gtag)
39
+ mockGA4 = jest.fn()
40
+ return Promise.resolve(mockGA4)
44
41
  })
45
42
  await trackEventPlugin.load(Context.system(), {} as Analytics)
46
43
  })
@@ -61,7 +58,7 @@ describe('GoogleAnalytics4Web.customEvent', () => {
61
58
  })
62
59
  await customEvent.track?.(context)
63
60
 
64
- expect(mockGA4.gtag).toHaveBeenCalledWith(
61
+ expect(mockGA4).toHaveBeenCalledWith(
65
62
  expect.anything(),
66
63
  expect.stringContaining('Custom_Event'),
67
64
  expect.objectContaining([{ paramOne: 'test123', paramThree: 123, paramTwo: 'test123' }])
@@ -1,7 +1,6 @@
1
1
  import { Subscription } from '@segment/browser-destination-runtime/types'
2
2
  import { Analytics, Context } from '@segment/analytics-next'
3
3
  import googleAnalytics4Web, { destination } from '../index'
4
- import { GA } from '../types'
5
4
 
6
5
  const subscriptions: Subscription[] = [
7
6
  {
@@ -25,7 +24,7 @@ describe('GoogleAnalytics4Web.generateLead', () => {
25
24
  measurementID: 'test123'
26
25
  }
27
26
 
28
- let mockGA4: GA
27
+ let mockGA4: typeof gtag
29
28
  let generateLeadEvent: any
30
29
  beforeEach(async () => {
31
30
  jest.restoreAllMocks()
@@ -37,10 +36,8 @@ describe('GoogleAnalytics4Web.generateLead', () => {
37
36
  generateLeadEvent = trackEventPlugin
38
37
 
39
38
  jest.spyOn(destination, 'initialize').mockImplementation(() => {
40
- mockGA4 = {
41
- gtag: jest.fn()
42
- }
43
- return Promise.resolve(mockGA4.gtag)
39
+ mockGA4 = jest.fn()
40
+ return Promise.resolve(mockGA4)
44
41
  })
45
42
  await trackEventPlugin.load(Context.system(), {} as Analytics)
46
43
  })
@@ -56,7 +53,7 @@ describe('GoogleAnalytics4Web.generateLead', () => {
56
53
  })
57
54
  await generateLeadEvent.track?.(context)
58
55
 
59
- expect(mockGA4.gtag).toHaveBeenCalledWith(
56
+ expect(mockGA4).toHaveBeenCalledWith(
60
57
  expect.anything(),
61
58
  expect.stringContaining('generate_lead'),
62
59
  expect.objectContaining({
@@ -1,7 +1,6 @@
1
1
  import { Subscription } from '@segment/browser-destination-runtime/types'
2
2
  import { Analytics, Context } from '@segment/analytics-next'
3
3
  import googleAnalytics4Web, { destination } from '../index'
4
- import { GA } from '../types'
5
4
 
6
5
  const subscriptions: Subscription[] = [
7
6
  {
@@ -34,10 +33,8 @@ describe('GoogleAnalytics4Web.login', () => {
34
33
  loginEvent = trackEventPlugin
35
34
 
36
35
  jest.spyOn(destination, 'initialize').mockImplementation(() => {
37
- mockGA4 = {
38
- gtag: jest.fn()
39
- }
40
- return Promise.resolve(mockGA4.gtag)
36
+ mockGA4 = jest.fn()
37
+ return Promise.resolve(mockGA4)
41
38
  })
42
39
  await trackEventPlugin.load(Context.system(), {} as Analytics)
43
40
  })
@@ -52,7 +49,7 @@ describe('GoogleAnalytics4Web.login', () => {
52
49
  })
53
50
  await loginEvent.track?.(context)
54
51
 
55
- expect(mockGA4.gtag).toHaveBeenCalledWith(
52
+ expect(mockGA4).toHaveBeenCalledWith(
56
53
  expect.anything(),
57
54
  expect.stringContaining('login'),
58
55
  expect.objectContaining({
@@ -1,7 +1,6 @@
1
1
  import { Subscription } from '@segment/browser-destination-runtime/types'
2
2
  import { Analytics, Context } from '@segment/analytics-next'
3
3
  import googleAnalytics4Web, { destination } from '../index'
4
- import { GA } from '../types'
5
4
 
6
5
  const subscriptions: Subscription[] = [
7
6
  {
@@ -50,7 +49,7 @@ describe('GoogleAnalytics4Web.purchase', () => {
50
49
  measurementID: 'test123'
51
50
  }
52
51
 
53
- let mockGA4: GA
52
+ let mockGA4: typeof gtag
54
53
  let purchaseEvent: any
55
54
  beforeEach(async () => {
56
55
  jest.restoreAllMocks()
@@ -62,10 +61,8 @@ describe('GoogleAnalytics4Web.purchase', () => {
62
61
  purchaseEvent = trackEventPlugin
63
62
 
64
63
  jest.spyOn(destination, 'initialize').mockImplementation(() => {
65
- mockGA4 = {
66
- gtag: jest.fn()
67
- }
68
- return Promise.resolve(mockGA4.gtag)
64
+ mockGA4 = jest.fn()
65
+ return Promise.resolve(mockGA4)
69
66
  })
70
67
  await trackEventPlugin.load(Context.system(), {} as Analytics)
71
68
  })
@@ -89,7 +86,7 @@ describe('GoogleAnalytics4Web.purchase', () => {
89
86
  })
90
87
  await purchaseEvent.track?.(context)
91
88
 
92
- expect(mockGA4.gtag).toHaveBeenCalledWith(
89
+ expect(mockGA4).toHaveBeenCalledWith(
93
90
  expect.anything(),
94
91
  expect.stringContaining('purchase'),
95
92
  expect.objectContaining({
@@ -1,7 +1,6 @@
1
1
  import { Subscription } from '@segment/browser-destination-runtime/types'
2
2
  import { Analytics, Context } from '@segment/analytics-next'
3
3
  import googleAnalytics4Web, { destination } from '../index'
4
- import { GA } from '../types'
5
4
 
6
5
  const subscriptions: Subscription[] = [
7
6
  {
@@ -50,7 +49,7 @@ describe('GoogleAnalytics4Web.refund', () => {
50
49
  measurementID: 'test123'
51
50
  }
52
51
 
53
- let mockGA4: GA
52
+ let mockGA4: typeof gtag
54
53
  let refundEvent: any
55
54
  beforeEach(async () => {
56
55
  jest.restoreAllMocks()
@@ -62,10 +61,8 @@ describe('GoogleAnalytics4Web.refund', () => {
62
61
  refundEvent = trackEventPlugin
63
62
 
64
63
  jest.spyOn(destination, 'initialize').mockImplementation(() => {
65
- mockGA4 = {
66
- gtag: jest.fn()
67
- }
68
- return Promise.resolve(mockGA4.gtag)
64
+ mockGA4 = jest.fn()
65
+ return Promise.resolve(mockGA4)
69
66
  })
70
67
  await trackEventPlugin.load(Context.system(), {} as Analytics)
71
68
  })
@@ -89,7 +86,7 @@ describe('GoogleAnalytics4Web.refund', () => {
89
86
  })
90
87
  await refundEvent.track?.(context)
91
88
 
92
- expect(mockGA4.gtag).toHaveBeenCalledWith(
89
+ expect(mockGA4).toHaveBeenCalledWith(
93
90
  expect.anything(),
94
91
  expect.stringContaining('refund'),
95
92
  expect.objectContaining({
@@ -1,7 +1,6 @@
1
1
  import { Subscription } from '@segment/browser-destination-runtime/types'
2
2
  import { Analytics, Context } from '@segment/analytics-next'
3
3
  import googleAnalytics4Web, { destination } from '../index'
4
- import { GA } from '../types'
5
4
 
6
5
  const subscriptions: Subscription[] = [
7
6
  {
@@ -47,7 +46,7 @@ describe('GoogleAnalytics4Web.removeFromCart', () => {
47
46
  measurementID: 'test123'
48
47
  }
49
48
 
50
- let mockGA4: GA
49
+ let mockGA4: typeof gtag
51
50
  let removeFromCartEvent: any
52
51
  beforeEach(async () => {
53
52
  jest.restoreAllMocks()
@@ -59,10 +58,8 @@ describe('GoogleAnalytics4Web.removeFromCart', () => {
59
58
  removeFromCartEvent = trackEventPlugin
60
59
 
61
60
  jest.spyOn(destination, 'initialize').mockImplementation(() => {
62
- mockGA4 = {
63
- gtag: jest.fn()
64
- }
65
- return Promise.resolve(mockGA4.gtag)
61
+ mockGA4 = jest.fn()
62
+ return Promise.resolve(mockGA4)
66
63
  })
67
64
  await trackEventPlugin.load(Context.system(), {} as Analytics)
68
65
  })
@@ -86,7 +83,7 @@ describe('GoogleAnalytics4Web.removeFromCart', () => {
86
83
 
87
84
  await removeFromCartEvent.track?.(context)
88
85
 
89
- expect(mockGA4.gtag).toHaveBeenCalledWith(
86
+ expect(mockGA4).toHaveBeenCalledWith(
90
87
  expect.anything(),
91
88
  expect.stringContaining('remove_from_cart'),
92
89
  expect.objectContaining({
@@ -1,7 +1,6 @@
1
1
  import { Subscription } from '@segment/browser-destination-runtime/types'
2
2
  import { Analytics, Context } from '@segment/analytics-next'
3
3
  import googleAnalytics4Web, { destination } from '../index'
4
- import { GA } from '../types'
5
4
 
6
5
  const subscriptions: Subscription[] = [
7
6
  {
@@ -22,7 +21,7 @@ describe('GoogleAnalytics4Web.search', () => {
22
21
  measurementID: 'test123'
23
22
  }
24
23
 
25
- let mockGA4: GA
24
+ let mockGA4: typeof gtag
26
25
  let searchEvent: any
27
26
  beforeEach(async () => {
28
27
  jest.restoreAllMocks()
@@ -34,10 +33,8 @@ describe('GoogleAnalytics4Web.search', () => {
34
33
  searchEvent = trackEventPlugin
35
34
 
36
35
  jest.spyOn(destination, 'initialize').mockImplementation(() => {
37
- mockGA4 = {
38
- gtag: jest.fn()
39
- }
40
- return Promise.resolve(mockGA4.gtag)
36
+ mockGA4 = jest.fn()
37
+ return Promise.resolve(mockGA4)
41
38
  })
42
39
  await trackEventPlugin.load(Context.system(), {} as Analytics)
43
40
  })
@@ -53,7 +50,7 @@ describe('GoogleAnalytics4Web.search', () => {
53
50
 
54
51
  await searchEvent.track?.(context)
55
52
 
56
- expect(mockGA4.gtag).toHaveBeenCalledWith(
53
+ expect(mockGA4).toHaveBeenCalledWith(
57
54
  expect.anything(),
58
55
  expect.stringContaining('search'),
59
56
  expect.objectContaining({
@@ -1,7 +1,6 @@
1
1
  import { Subscription } from '@segment/browser-destination-runtime/types'
2
2
  import { Analytics, Context } from '@segment/analytics-next'
3
3
  import googleAnalytics4Web, { destination } from '../index'
4
- import { GA } from '../types'
5
4
 
6
5
  const subscriptions: Subscription[] = [
7
6
  {
@@ -44,7 +43,7 @@ describe('GoogleAnalytics4Web.selectItem', () => {
44
43
  measurementID: 'test123'
45
44
  }
46
45
 
47
- let mockGA4: GA
46
+ let mockGA4: typeof gtag
48
47
  let selectItemEvent: any
49
48
  beforeEach(async () => {
50
49
  jest.restoreAllMocks()
@@ -56,10 +55,8 @@ describe('GoogleAnalytics4Web.selectItem', () => {
56
55
  selectItemEvent = trackEventPlugin
57
56
 
58
57
  jest.spyOn(destination, 'initialize').mockImplementation(() => {
59
- mockGA4 = {
60
- gtag: jest.fn()
61
- }
62
- return Promise.resolve(mockGA4.gtag)
58
+ mockGA4 = jest.fn()
59
+ return Promise.resolve(mockGA4)
63
60
  })
64
61
  await trackEventPlugin.load(Context.system(), {} as Analytics)
65
62
  })
@@ -83,7 +80,7 @@ describe('GoogleAnalytics4Web.selectItem', () => {
83
80
 
84
81
  await selectItemEvent.track?.(context)
85
82
 
86
- expect(mockGA4.gtag).toHaveBeenCalledWith(
83
+ expect(mockGA4).toHaveBeenCalledWith(
87
84
  expect.anything(),
88
85
  expect.stringContaining('select_item'),
89
86
  expect.objectContaining({
@@ -1,7 +1,6 @@
1
1
  import { Subscription } from '@segment/browser-destination-runtime/types'
2
2
  import { Analytics, Context } from '@segment/analytics-next'
3
3
  import googleAnalytics4Web, { destination } from '../index'
4
- import { GA } from '../types'
5
4
 
6
5
  const subscriptions: Subscription[] = [
7
6
  {
@@ -53,7 +52,7 @@ describe('GoogleAnalytics4Web.selectPromotion', () => {
53
52
  measurementID: 'test123'
54
53
  }
55
54
 
56
- let mockGA4: GA
55
+ let mockGA4: typeof gtag
57
56
  let selectPromotionEvent: any
58
57
  beforeEach(async () => {
59
58
  jest.restoreAllMocks()
@@ -65,10 +64,8 @@ describe('GoogleAnalytics4Web.selectPromotion', () => {
65
64
  selectPromotionEvent = trackEventPlugin
66
65
 
67
66
  jest.spyOn(destination, 'initialize').mockImplementation(() => {
68
- mockGA4 = {
69
- gtag: jest.fn()
70
- }
71
- return Promise.resolve(mockGA4.gtag)
67
+ mockGA4 = jest.fn()
68
+ return Promise.resolve(mockGA4)
72
69
  })
73
70
  await trackEventPlugin.load(Context.system(), {} as Analytics)
74
71
  })
@@ -95,7 +92,7 @@ describe('GoogleAnalytics4Web.selectPromotion', () => {
95
92
 
96
93
  await selectPromotionEvent.track?.(context)
97
94
 
98
- expect(mockGA4.gtag).toHaveBeenCalledWith(
95
+ expect(mockGA4).toHaveBeenCalledWith(
99
96
  expect.anything(),
100
97
  expect.stringContaining('select_promotion'),
101
98
  expect.objectContaining({
@@ -1,7 +1,6 @@
1
1
  import { Subscription } from '@segment/browser-destination-runtime/types'
2
2
  import { Analytics, Context } from '@segment/analytics-next'
3
3
  import googleAnalytics4Web, { destination } from '../index'
4
- import { GA } from '../types'
5
4
 
6
5
  const subscriptions: Subscription[] = [
7
6
  {
@@ -22,7 +21,7 @@ describe('GoogleAnalytics4Web.signUp', () => {
22
21
  measurementID: 'test123'
23
22
  }
24
23
 
25
- let mockGA4: GA
24
+ let mockGA4: typeof gtag
26
25
  let signUpEvent: any
27
26
  beforeEach(async () => {
28
27
  jest.restoreAllMocks()
@@ -34,10 +33,8 @@ describe('GoogleAnalytics4Web.signUp', () => {
34
33
  signUpEvent = trackEventPlugin
35
34
 
36
35
  jest.spyOn(destination, 'initialize').mockImplementation(() => {
37
- mockGA4 = {
38
- gtag: jest.fn()
39
- }
40
- return Promise.resolve(mockGA4.gtag)
36
+ mockGA4 = jest.fn()
37
+ return Promise.resolve(mockGA4)
41
38
  })
42
39
  await trackEventPlugin.load(Context.system(), {} as Analytics)
43
40
  })
@@ -53,7 +50,7 @@ describe('GoogleAnalytics4Web.signUp', () => {
53
50
 
54
51
  await signUpEvent.track?.(context)
55
52
 
56
- expect(mockGA4.gtag).toHaveBeenCalledWith(
53
+ expect(mockGA4).toHaveBeenCalledWith(
57
54
  expect.anything(),
58
55
  expect.stringContaining('sign_up'),
59
56
  expect.objectContaining({ method: 'Google' })
@@ -1,7 +1,6 @@
1
1
  import { Subscription } from '@segment/browser-destination-runtime/types'
2
2
  import { Analytics, Context } from '@segment/analytics-next'
3
3
  import googleAnalytics4Web, { destination } from '../index'
4
- import { GA } from '../types'
5
4
 
6
5
  const subscriptions: Subscription[] = [
7
6
  {
@@ -44,7 +43,7 @@ describe('GoogleAnalytics4Web.viewCart', () => {
44
43
  measurementID: 'test123'
45
44
  }
46
45
 
47
- let mockGA4: GA
46
+ let mockGA4: typeof gtag
48
47
  let viewCartEvent: any
49
48
  beforeEach(async () => {
50
49
  jest.restoreAllMocks()
@@ -56,10 +55,8 @@ describe('GoogleAnalytics4Web.viewCart', () => {
56
55
  viewCartEvent = trackEventPlugin
57
56
 
58
57
  jest.spyOn(destination, 'initialize').mockImplementation(() => {
59
- mockGA4 = {
60
- gtag: jest.fn()
61
- }
62
- return Promise.resolve(mockGA4.gtag)
58
+ mockGA4 = jest.fn()
59
+ return Promise.resolve(mockGA4)
63
60
  })
64
61
  await trackEventPlugin.load(Context.system(), {} as Analytics)
65
62
  })
@@ -83,7 +80,7 @@ describe('GoogleAnalytics4Web.viewCart', () => {
83
80
 
84
81
  await viewCartEvent.track?.(context)
85
82
 
86
- expect(mockGA4.gtag).toHaveBeenCalledWith(
83
+ expect(mockGA4).toHaveBeenCalledWith(
87
84
  expect.anything(),
88
85
  expect.stringContaining('view_cart'),
89
86
  expect.objectContaining({
@@ -1,7 +1,6 @@
1
1
  import { Subscription } from '@segment/browser-destination-runtime/types'
2
2
  import { Analytics, Context } from '@segment/analytics-next'
3
3
  import googleAnalytics4Web, { destination } from '../index'
4
- import { GA } from '../types'
5
4
 
6
5
  const subscriptions: Subscription[] = [
7
6
  {
@@ -44,7 +43,7 @@ describe('GoogleAnalytics4Web.viewItem', () => {
44
43
  measurementID: 'test123'
45
44
  }
46
45
 
47
- let mockGA4: GA
46
+ let mockGA4: typeof gtag
48
47
  let viewItemEvent: any
49
48
  beforeEach(async () => {
50
49
  jest.restoreAllMocks()
@@ -56,10 +55,8 @@ describe('GoogleAnalytics4Web.viewItem', () => {
56
55
  viewItemEvent = trackEventPlugin
57
56
 
58
57
  jest.spyOn(destination, 'initialize').mockImplementation(() => {
59
- mockGA4 = {
60
- gtag: jest.fn()
61
- }
62
- return Promise.resolve(mockGA4.gtag)
58
+ mockGA4 = jest.fn()
59
+ return Promise.resolve(mockGA4)
63
60
  })
64
61
  await trackEventPlugin.load(Context.system(), {} as Analytics)
65
62
  })
@@ -83,7 +80,7 @@ describe('GoogleAnalytics4Web.viewItem', () => {
83
80
 
84
81
  await viewItemEvent.track?.(context)
85
82
 
86
- expect(mockGA4.gtag).toHaveBeenCalledWith(
83
+ expect(mockGA4).toHaveBeenCalledWith(
87
84
  expect.anything(),
88
85
  expect.stringContaining('view_item'),
89
86
  expect.objectContaining({
@@ -1,7 +1,6 @@
1
1
  import { Subscription } from '@segment/browser-destination-runtime/types'
2
2
  import { Analytics, Context } from '@segment/analytics-next'
3
3
  import googleAnalytics4Web, { destination } from '../index'
4
- import { GA } from '../types'
5
4
 
6
5
  const subscriptions: Subscription[] = [
7
6
  {
@@ -44,7 +43,7 @@ describe('GoogleAnalytics4Web.viewItemList', () => {
44
43
  measurementID: 'test123'
45
44
  }
46
45
 
47
- let mockGA4: GA
46
+ let mockGA4: typeof gtag
48
47
  let viewItemListEvent: any
49
48
  beforeEach(async () => {
50
49
  jest.restoreAllMocks()
@@ -56,10 +55,8 @@ describe('GoogleAnalytics4Web.viewItemList', () => {
56
55
  viewItemListEvent = trackEventPlugin
57
56
 
58
57
  jest.spyOn(destination, 'initialize').mockImplementation(() => {
59
- mockGA4 = {
60
- gtag: jest.fn()
61
- }
62
- return Promise.resolve(mockGA4.gtag)
58
+ mockGA4 = jest.fn()
59
+ return Promise.resolve(mockGA4)
63
60
  })
64
61
  await trackEventPlugin.load(Context.system(), {} as Analytics)
65
62
  })
@@ -83,7 +80,7 @@ describe('GoogleAnalytics4Web.viewItemList', () => {
83
80
 
84
81
  await viewItemListEvent.track?.(context)
85
82
 
86
- expect(mockGA4.gtag).toHaveBeenCalledWith(
83
+ expect(mockGA4).toHaveBeenCalledWith(
87
84
  expect.anything(),
88
85
  expect.stringContaining('view_item_list'),
89
86
  expect.objectContaining({
@@ -1,7 +1,6 @@
1
1
  import { Subscription } from '@segment/browser-destination-runtime/types'
2
2
  import { Analytics, Context } from '@segment/analytics-next'
3
3
  import googleAnalytics4Web, { destination } from '../index'
4
- import { GA } from '../types'
5
4
 
6
5
  const subscriptions: Subscription[] = [
7
6
  {
@@ -53,7 +52,7 @@ describe('GoogleAnalytics4Web.viewPromotion', () => {
53
52
  measurementID: 'test123'
54
53
  }
55
54
 
56
- let mockGA4: GA
55
+ let mockGA4: typeof gtag
57
56
  let viewPromotionEvent: any
58
57
  beforeEach(async () => {
59
58
  jest.restoreAllMocks()
@@ -65,10 +64,8 @@ describe('GoogleAnalytics4Web.viewPromotion', () => {
65
64
  viewPromotionEvent = trackEventPlugin
66
65
 
67
66
  jest.spyOn(destination, 'initialize').mockImplementation(() => {
68
- mockGA4 = {
69
- gtag: jest.fn()
70
- }
71
- return Promise.resolve(mockGA4.gtag)
67
+ mockGA4 = jest.fn()
68
+ return Promise.resolve(mockGA4)
72
69
  })
73
70
  await trackEventPlugin.load(Context.system(), {} as Analytics)
74
71
  })
@@ -95,7 +92,7 @@ describe('GoogleAnalytics4Web.viewPromotion', () => {
95
92
 
96
93
  await viewPromotionEvent.track?.(context)
97
94
 
98
- expect(mockGA4.gtag).toHaveBeenCalledWith(
95
+ expect(mockGA4).toHaveBeenCalledWith(
99
96
  expect.anything(),
100
97
  expect.stringContaining('view_promotion'),
101
98
  expect.objectContaining({
package/src/index.ts CHANGED
@@ -30,6 +30,8 @@ declare global {
30
30
  }
31
31
  }
32
32
 
33
+ type ConsentParamsArg = 'granted' | 'denied' | undefined
34
+
33
35
  const presets: DestinationDefinition['presets'] = [
34
36
  {
35
37
  name: `Set Configuration Fields`,
@@ -153,8 +155,8 @@ export const destination: BrowserDestinationDefinition<Settings, Function> = {
153
155
  window.gtag('js', new Date())
154
156
  if (settings.enableConsentMode) {
155
157
  window.gtag('consent', 'default', {
156
- ad_storage: settings.defaultAdsStorageConsentState,
157
- analytics_storage: settings.defaultAnalyticsStorageConsentState,
158
+ ad_storage: settings.defaultAdsStorageConsentState as ConsentParamsArg,
159
+ analytics_storage: settings.defaultAnalyticsStorageConsentState as ConsentParamsArg,
158
160
  wait_for_update: settings.waitTimeToUpdateConsentStage
159
161
  })
160
162
  }
@@ -4,6 +4,8 @@ import type { Payload } from './generated-types'
4
4
  import { user_id, user_properties } from '../ga4-properties'
5
5
  import { updateUser } from '../ga4-functions'
6
6
 
7
+ type ConsentParamsArg = 'granted' | 'denied' | undefined
8
+
7
9
  // Change from unknown to the partner SDK types
8
10
  const action: BrowserActionDefinition<Settings, Function, Payload> = {
9
11
  title: 'Set Configuration Fields',
@@ -96,8 +98,8 @@ const action: BrowserActionDefinition<Settings, Function, Payload> = {
96
98
  updateUser(payload.user_id, payload.user_properties, gtag)
97
99
  if (settings.enableConsentMode) {
98
100
  window.gtag('consent', 'update', {
99
- ad_storage: payload.ads_storage_consent_state,
100
- analytics_storage: payload.analytics_storage_consent_state
101
+ ad_storage: payload.ads_storage_consent_state as ConsentParamsArg,
102
+ analytics_storage: payload.analytics_storage_consent_state as ConsentParamsArg
101
103
  })
102
104
  }
103
105
  type ConfigType = { [key: string]: unknown }
@@ -119,6 +121,9 @@ const action: BrowserActionDefinition<Settings, Function, Payload> = {
119
121
  if (payload.user_id) {
120
122
  config.user_id = payload.user_id
121
123
  }
124
+ if (payload.user_properties) {
125
+ config.user_properties = payload.user_properties
126
+ }
122
127
  if (payload.page_title) {
123
128
  config.page_title = payload.page_title
124
129
  }
@@ -1,3 +0,0 @@
1
- export declare type GA = {
2
- gtag: Function;
3
- };
package/dist/cjs/types.js DELETED
@@ -1,3 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- //# sourceMappingURL=types.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":""}
@@ -1,3 +0,0 @@
1
- export declare type GA = {
2
- gtag: Function;
3
- };