@segment/analytics-browser-actions-facebook-conversions-api-web 1.9.1-staging-99a2d468f.1 → 1.11.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/functions.d.ts +0 -1
- package/dist/cjs/functions.js +2 -11
- package/dist/cjs/functions.js.map +1 -1
- package/dist/cjs/generated-types.d.ts +1 -0
- package/dist/cjs/index.d.ts +6 -2
- package/dist/cjs/index.js +17 -5
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/send/depends-on.js +11 -40
- package/dist/cjs/send/depends-on.js.map +1 -1
- package/dist/cjs/send/fields.js +18 -5
- package/dist/cjs/send/fields.js.map +1 -1
- package/dist/cjs/send/functions.d.ts +2 -2
- package/dist/cjs/send/functions.js +40 -29
- package/dist/cjs/send/functions.js.map +1 -1
- package/dist/cjs/send/generated-types.d.ts +2 -0
- package/dist/cjs/send/index.d.ts +5 -2
- package/dist/cjs/send/index.js +1 -1
- package/dist/cjs/send/index.js.map +1 -1
- package/dist/cjs/types.d.ts +10 -0
- package/dist/cjs/types.js.map +1 -1
- package/dist/esm/functions.d.ts +0 -1
- package/dist/esm/functions.js +2 -10
- package/dist/esm/functions.js.map +1 -1
- package/dist/esm/generated-types.d.ts +1 -0
- package/dist/esm/index.d.ts +6 -2
- package/dist/esm/index.js +17 -5
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/send/depends-on.js +11 -40
- package/dist/esm/send/depends-on.js.map +1 -1
- package/dist/esm/send/fields.js +18 -5
- package/dist/esm/send/fields.js.map +1 -1
- package/dist/esm/send/functions.d.ts +2 -2
- package/dist/esm/send/functions.js +40 -29
- package/dist/esm/send/functions.js.map +1 -1
- package/dist/esm/send/generated-types.d.ts +2 -0
- package/dist/esm/send/index.d.ts +5 -2
- package/dist/esm/send/index.js +1 -1
- package/dist/esm/send/index.js.map +1 -1
- package/dist/esm/types.d.ts +10 -0
- package/dist/esm/types.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +3 -3
- package/src/__tests__/functions.test.ts +159 -0
- package/src/constants.ts +1 -1
- package/src/functions.ts +66 -65
- package/src/generated-types.ts +4 -0
- package/src/index.ts +43 -26
- package/src/send/__tests__/depends-on.test.ts +28 -0
- package/src/send/__tests__/functions.test.ts +1178 -0
- package/src/send/depends-on.ts +41 -69
- package/src/send/fields.ts +304 -299
- package/src/send/functions.ts +213 -153
- package/src/send/generated-types.ts +10 -2
- package/src/send/index.ts +4 -4
- package/src/types.ts +33 -21
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@segment/analytics-browser-actions-facebook-conversions-api-web",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.11.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -16,10 +16,10 @@
|
|
|
16
16
|
},
|
|
17
17
|
"typings": "./dist/esm",
|
|
18
18
|
"dependencies": {
|
|
19
|
-
"@segment/browser-destination-runtime": "1.
|
|
19
|
+
"@segment/browser-destination-runtime": "^1.93.0"
|
|
20
20
|
},
|
|
21
21
|
"peerDependencies": {
|
|
22
22
|
"@segment/analytics-next": ">=1.55.0"
|
|
23
23
|
},
|
|
24
|
-
"gitHead": "
|
|
24
|
+
"gitHead": "bda78db80a4ab33f11968bea94336855d37d3805"
|
|
25
25
|
}
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import { initScript, setStorageInitCount, storageFallback } from '../functions'
|
|
2
|
+
import { LDU } from '../types'
|
|
3
|
+
|
|
4
|
+
describe('Facebook Conversions API Web - Main Functions', () => {
|
|
5
|
+
let mockAnalytics
|
|
6
|
+
|
|
7
|
+
beforeEach(() => {
|
|
8
|
+
// Reset window.fbq
|
|
9
|
+
delete window.fbq
|
|
10
|
+
delete window._fbq
|
|
11
|
+
|
|
12
|
+
mockAnalytics = {
|
|
13
|
+
storage: {
|
|
14
|
+
get: jest.fn(),
|
|
15
|
+
set: jest.fn()
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// Mock localStorage
|
|
20
|
+
Storage.prototype.getItem = jest.fn()
|
|
21
|
+
Storage.prototype.setItem = jest.fn()
|
|
22
|
+
})
|
|
23
|
+
|
|
24
|
+
afterEach(() => {
|
|
25
|
+
jest.restoreAllMocks()
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
describe('initScript', () => {
|
|
29
|
+
it('should initialize Facebook Pixel with basic settings', () => {
|
|
30
|
+
const settings = {
|
|
31
|
+
pixelId: 'test-pixel-123',
|
|
32
|
+
ldu: LDU.Disabled.key
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
initScript(settings, mockAnalytics)
|
|
36
|
+
|
|
37
|
+
expect(window.fbq).toBeDefined()
|
|
38
|
+
expect(typeof window.fbq).toBe('function')
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
it('should set LDU to disabled when configured', () => {
|
|
42
|
+
const settings = {
|
|
43
|
+
pixelId: 'test-pixel-123',
|
|
44
|
+
ldu: LDU.Disabled.key
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
initScript(settings, mockAnalytics)
|
|
48
|
+
|
|
49
|
+
expect(window.fbq).toBeDefined()
|
|
50
|
+
expect(mockAnalytics.storage.set).toHaveBeenCalledWith('fb_pixel_init_count', '1')
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
it('should set LDU with California state when configured', () => {
|
|
54
|
+
const settings = {
|
|
55
|
+
pixelId: 'test-pixel-123',
|
|
56
|
+
ldu: LDU.California.key
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
initScript(settings, mockAnalytics)
|
|
60
|
+
|
|
61
|
+
expect(window.fbq).toBeDefined()
|
|
62
|
+
expect(mockAnalytics.storage.set).toHaveBeenCalledWith('fb_pixel_init_count', '1')
|
|
63
|
+
})
|
|
64
|
+
|
|
65
|
+
it('should disable push state when configured', () => {
|
|
66
|
+
const settings = {
|
|
67
|
+
pixelId: 'test-pixel-123',
|
|
68
|
+
ldu: LDU.Disabled.key,
|
|
69
|
+
disablePushState: true
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
initScript(settings, mockAnalytics)
|
|
73
|
+
|
|
74
|
+
expect(window.fbq.disablePushState).toBe(true)
|
|
75
|
+
})
|
|
76
|
+
|
|
77
|
+
it('should set init count in storage', () => {
|
|
78
|
+
const settings = {
|
|
79
|
+
pixelId: 'test-pixel-123',
|
|
80
|
+
ldu: LDU.Disabled.key
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
initScript(settings, mockAnalytics)
|
|
84
|
+
|
|
85
|
+
expect(mockAnalytics.storage.set).toHaveBeenCalledWith('fb_pixel_init_count', '1')
|
|
86
|
+
})
|
|
87
|
+
|
|
88
|
+
it('should initialize pixel with stored user data', () => {
|
|
89
|
+
const userData = {
|
|
90
|
+
em: 'test@example.com',
|
|
91
|
+
fn: 'John',
|
|
92
|
+
ln: 'Doe'
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
mockAnalytics.storage.get.mockReturnValue(JSON.stringify(userData))
|
|
96
|
+
|
|
97
|
+
const settings = {
|
|
98
|
+
pixelId: 'test-pixel-123',
|
|
99
|
+
ldu: LDU.Disabled.key
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
initScript(settings, mockAnalytics)
|
|
103
|
+
|
|
104
|
+
expect(window.fbq).toBeDefined()
|
|
105
|
+
expect(mockAnalytics.storage.get).toHaveBeenCalledWith('fb_user_data')
|
|
106
|
+
})
|
|
107
|
+
})
|
|
108
|
+
|
|
109
|
+
describe('setStorageInitCount', () => {
|
|
110
|
+
it('should set init count in storage', () => {
|
|
111
|
+
setStorageInitCount(mockAnalytics, 1)
|
|
112
|
+
|
|
113
|
+
expect(mockAnalytics.storage.set).toHaveBeenCalledWith('fb_pixel_init_count', '1')
|
|
114
|
+
})
|
|
115
|
+
|
|
116
|
+
it('should set init count to 2', () => {
|
|
117
|
+
setStorageInitCount(mockAnalytics, 2)
|
|
118
|
+
|
|
119
|
+
expect(mockAnalytics.storage.set).toHaveBeenCalledWith('fb_pixel_init_count', '2')
|
|
120
|
+
})
|
|
121
|
+
})
|
|
122
|
+
|
|
123
|
+
describe('storageFallback', () => {
|
|
124
|
+
it('should get value from localStorage', () => {
|
|
125
|
+
Storage.prototype.getItem.mockReturnValue('test-value')
|
|
126
|
+
|
|
127
|
+
const value = storageFallback.get('test-key')
|
|
128
|
+
|
|
129
|
+
expect(Storage.prototype.getItem).toHaveBeenCalledWith('test-key')
|
|
130
|
+
expect(value).toBe('test-value')
|
|
131
|
+
})
|
|
132
|
+
|
|
133
|
+
it('should return null if localStorage throws error', () => {
|
|
134
|
+
Storage.prototype.getItem.mockImplementation(() => {
|
|
135
|
+
throw new Error('Storage not available')
|
|
136
|
+
})
|
|
137
|
+
|
|
138
|
+
const value = storageFallback.get('test-key')
|
|
139
|
+
|
|
140
|
+
expect(value).toBeNull()
|
|
141
|
+
})
|
|
142
|
+
|
|
143
|
+
it('should set value in localStorage', () => {
|
|
144
|
+
storageFallback.set('test-key', 'test-value')
|
|
145
|
+
|
|
146
|
+
expect(Storage.prototype.setItem).toHaveBeenCalledWith('test-key', 'test-value')
|
|
147
|
+
})
|
|
148
|
+
|
|
149
|
+
it('should silently fail if localStorage.setItem throws error', () => {
|
|
150
|
+
Storage.prototype.setItem.mockImplementation(() => {
|
|
151
|
+
throw new Error('Storage not available')
|
|
152
|
+
})
|
|
153
|
+
|
|
154
|
+
expect(() => {
|
|
155
|
+
storageFallback.set('test-key', 'test-value')
|
|
156
|
+
}).not.toThrow()
|
|
157
|
+
})
|
|
158
|
+
})
|
|
159
|
+
})
|
package/src/constants.ts
CHANGED
package/src/functions.ts
CHANGED
|
@@ -1,52 +1,64 @@
|
|
|
1
|
-
import { WindowWithOptionalFbq, InitOptions, LDU, UserData, FBClient
|
|
1
|
+
import { WindowWithOptionalFbq, InitOptions, LDU, UserData, FBClient} from './types'
|
|
2
2
|
import type { Settings } from './generated-types'
|
|
3
|
-
import { USER_DATA_KEY, INIT_COUNT_KEY
|
|
3
|
+
import { USER_DATA_KEY, INIT_COUNT_KEY} from './constants'
|
|
4
4
|
import { UniversalStorage, Analytics } from '@segment/analytics-next'
|
|
5
5
|
|
|
6
6
|
export function initScript(settings: Settings, analytics: Analytics) {
|
|
7
|
-
const {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
7
|
+
const {
|
|
8
|
+
pixelId,
|
|
9
|
+
disablePushState,
|
|
10
|
+
disableAutoConfig,
|
|
11
|
+
disableFirstPartyCookies,
|
|
12
|
+
agent,
|
|
13
|
+
ldu
|
|
14
|
+
} = settings as Settings & { ldu: keyof typeof LDU }
|
|
15
|
+
|
|
16
|
+
(function(
|
|
17
|
+
f: WindowWithOptionalFbq,
|
|
18
|
+
b: Document,
|
|
19
|
+
e: 'script',
|
|
20
|
+
v: string,
|
|
21
|
+
n: FBClient | undefined = undefined,
|
|
22
|
+
t: HTMLScriptElement | undefined = undefined,
|
|
17
23
|
s: Element | null = null
|
|
18
|
-
)
|
|
19
|
-
if (f.fbq) return
|
|
20
|
-
n = f.fbq = function
|
|
24
|
+
){
|
|
25
|
+
if (f.fbq) return;
|
|
26
|
+
n = f.fbq = function() {
|
|
21
27
|
/* eslint-disable */
|
|
22
28
|
// @ts-expect-error - n is defined by the time this executes
|
|
23
|
-
n.callMethod ? n.callMethod.apply(n, arguments) : n.queue.push(arguments)
|
|
29
|
+
n.callMethod ? n.callMethod.apply(n, arguments) : n.queue.push(arguments);
|
|
24
30
|
/* eslint-enable */
|
|
25
|
-
}
|
|
26
|
-
if (!f._fbq) f._fbq = n
|
|
27
|
-
n.push = n
|
|
28
|
-
n.loaded = true
|
|
29
|
-
n.version = '2.0'
|
|
30
|
-
n.queue = []
|
|
31
|
-
t = b.createElement(e)
|
|
32
|
-
t.async = true
|
|
33
|
-
t.src = v
|
|
34
|
-
s = b.getElementsByTagName(e)[0]
|
|
31
|
+
};
|
|
32
|
+
if (!f._fbq) f._fbq = n;
|
|
33
|
+
n.push = n;
|
|
34
|
+
n.loaded = true;
|
|
35
|
+
n.version = '2.0';
|
|
36
|
+
n.queue = [];
|
|
37
|
+
t = b.createElement(e);
|
|
38
|
+
t.async = true;
|
|
39
|
+
t.src = v;
|
|
40
|
+
s = b.getElementsByTagName(e)[0];
|
|
35
41
|
if (s && s.parentNode) {
|
|
36
|
-
s.parentNode.insertBefore(t, s)
|
|
42
|
+
s.parentNode.insertBefore(t, s);
|
|
37
43
|
}
|
|
38
|
-
})(
|
|
39
|
-
|
|
40
|
-
|
|
44
|
+
})(
|
|
45
|
+
window,
|
|
46
|
+
document,
|
|
47
|
+
'script',
|
|
48
|
+
'https://connect.facebook.net/en_US/fbevents.js'
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
if(ldu === LDU.Disabled.key) {
|
|
41
52
|
window.fbq('dataProcessingOptions', [])
|
|
42
|
-
}
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
43
55
|
const lduObj = getLDU(ldu)
|
|
44
56
|
window.fbq('dataProcessingOptions', ['LDU'], lduObj.country, lduObj.state)
|
|
45
57
|
}
|
|
46
58
|
|
|
47
|
-
if
|
|
59
|
+
if(disablePushState) {
|
|
48
60
|
window.fbq.disablePushState = true
|
|
49
|
-
}
|
|
61
|
+
}
|
|
50
62
|
|
|
51
63
|
if (disableAutoConfig) {
|
|
52
64
|
window.fbq('set', 'autoConfig', false, pixelId)
|
|
@@ -57,13 +69,13 @@ export function initScript(settings: Settings, analytics: Analytics) {
|
|
|
57
69
|
}
|
|
58
70
|
|
|
59
71
|
const userData = getStoredUserData(analytics)
|
|
60
|
-
const options: InitOptions | undefined = agent ? { agent } : undefined
|
|
72
|
+
const options: InitOptions | undefined = ( agent ? { agent } : undefined)
|
|
61
73
|
const initArgs: [string, UserData?, InitOptions?] = [pixelId]
|
|
62
74
|
|
|
63
75
|
if (userData && Object.keys(userData).length > 0) {
|
|
64
|
-
initArgs.push(userData)
|
|
76
|
+
initArgs.push(userData);
|
|
65
77
|
if (options) {
|
|
66
|
-
initArgs.push(options)
|
|
78
|
+
initArgs.push(options);
|
|
67
79
|
}
|
|
68
80
|
} else if (options) {
|
|
69
81
|
initArgs.push(undefined, options)
|
|
@@ -72,9 +84,8 @@ export function initScript(settings: Settings, analytics: Analytics) {
|
|
|
72
84
|
window.fbq('init', ...initArgs)
|
|
73
85
|
|
|
74
86
|
setStorageInitCount(analytics, 1)
|
|
75
|
-
deleteStorageUserData(analytics)
|
|
76
87
|
|
|
77
|
-
if
|
|
88
|
+
if(!disablePushState) {
|
|
78
89
|
window.fbq('trackSingle', pixelId, 'PageView')
|
|
79
90
|
}
|
|
80
91
|
}
|
|
@@ -101,34 +112,24 @@ export function setStorageInitCount(analytics: Analytics, count: number) {
|
|
|
101
112
|
storage.set(INIT_COUNT_KEY, `${count}`)
|
|
102
113
|
}
|
|
103
114
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
typeof parsed !== 'object' ||
|
|
118
|
-
Array.isArray(parsed) ||
|
|
119
|
-
Object.keys(parsed as object).length === 0
|
|
120
|
-
) {
|
|
121
|
-
return undefined
|
|
122
|
-
}
|
|
123
|
-
return parsed as UserData
|
|
124
|
-
} catch {
|
|
125
|
-
return undefined
|
|
115
|
+
function getStoredUserData(analytics: Analytics): UserData | undefined {
|
|
116
|
+
const storage = (analytics.storage as UniversalStorage<Record<string, string>>) ?? storageFallback
|
|
117
|
+
const userDataFromStorage: string | null = storage.get(USER_DATA_KEY)
|
|
118
|
+
if(userDataFromStorage) {
|
|
119
|
+
try {
|
|
120
|
+
const parsed = JSON.parse(userDataFromStorage)
|
|
121
|
+
if(!parsed || typeof parsed !== 'object' || Array.isArray(parsed) || Object.keys(parsed as object).length === 0) {
|
|
122
|
+
return undefined
|
|
123
|
+
}
|
|
124
|
+
return parsed as UserData
|
|
125
|
+
} catch {
|
|
126
|
+
return undefined
|
|
127
|
+
}
|
|
126
128
|
}
|
|
127
|
-
|
|
128
|
-
return undefined
|
|
129
|
+
return undefined
|
|
129
130
|
}
|
|
130
131
|
|
|
131
132
|
function getLDU(ldu: keyof typeof LDU) {
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
}
|
|
133
|
+
const lduObj = LDU[ldu]
|
|
134
|
+
return { country: lduObj.country, state: lduObj.state }
|
|
135
|
+
}
|
package/src/generated-types.ts
CHANGED
|
@@ -25,4 +25,8 @@ export interface Settings {
|
|
|
25
25
|
* Specify if and how Limited Data Use should apply.
|
|
26
26
|
*/
|
|
27
27
|
ldu: string
|
|
28
|
+
/**
|
|
29
|
+
* If enabled, uses Facebook’s Parameter Builder library to help ensure that User Data values are properly formatted before being sent to Facebook.
|
|
30
|
+
*/
|
|
31
|
+
formatUserDataWithParamBuilder?: boolean
|
|
28
32
|
}
|
package/src/index.ts
CHANGED
|
@@ -3,17 +3,18 @@ import type { BrowserDestinationDefinition } from '@segment/browser-destination-
|
|
|
3
3
|
import { browserDestination } from '@segment/browser-destination-runtime/shim'
|
|
4
4
|
import send from './send'
|
|
5
5
|
import { initScript } from './functions'
|
|
6
|
-
import { FBClient, LDU } from './types'
|
|
6
|
+
import { FBClient, FBClientParamBuilder, LDU } from './types'
|
|
7
7
|
import { defaultValues } from '@segment/actions-core'
|
|
8
8
|
|
|
9
9
|
declare global {
|
|
10
10
|
interface Window {
|
|
11
|
-
fbq: FBClient
|
|
11
|
+
fbq: FBClient,
|
|
12
12
|
_fbq: FBClient
|
|
13
|
+
clientParamBuilder: FBClientParamBuilder | undefined
|
|
13
14
|
}
|
|
14
15
|
}
|
|
15
16
|
|
|
16
|
-
export const destination: BrowserDestinationDefinition<Settings, FBClient> = {
|
|
17
|
+
export const destination: BrowserDestinationDefinition<Settings, { fbq: FBClient, clientParamBuilder: FBClientParamBuilder | undefined }> = {
|
|
17
18
|
name: 'Facebook Conversions Api Web',
|
|
18
19
|
slug: 'actions-facebook-conversions-api-web',
|
|
19
20
|
mode: 'device',
|
|
@@ -23,25 +24,22 @@ export const destination: BrowserDestinationDefinition<Settings, FBClient> = {
|
|
|
23
24
|
description: 'The Pixel ID associated with your Facebook Pixel.',
|
|
24
25
|
label: 'Pixel ID',
|
|
25
26
|
type: 'string',
|
|
26
|
-
required: true
|
|
27
|
+
required: true
|
|
27
28
|
},
|
|
28
29
|
disablePushState: {
|
|
29
|
-
description:
|
|
30
|
-
'If set to true, prevents Facebook Pixel from sending PageView events on history state changes. Set to true if you want to trigger PageView events manually via the pageView Action.',
|
|
30
|
+
description: "If set to true, prevents Facebook Pixel from sending PageView events on history state changes. Set to true if you want to trigger PageView events manually via the pageView Action.",
|
|
31
31
|
label: 'Disable Push State',
|
|
32
32
|
type: 'boolean',
|
|
33
33
|
default: false
|
|
34
34
|
},
|
|
35
35
|
disableAutoConfig: {
|
|
36
|
-
description:
|
|
37
|
-
'Control whether Facebook’s Meta Pixel automatically collects additional page and button data to optimize ads and measurement. When this toggle is on, Auto Config is disabled and only basic pixel tracking will occur. Turning it off enables Auto Config, allowing the Pixel to automatically send page metadata and button interactions to improve ad delivery and reporting.',
|
|
36
|
+
description: "Control whether Facebook’s Meta Pixel automatically collects additional page and button data to optimize ads and measurement. When this toggle is on, Auto Config is disabled and only basic pixel tracking will occur. Turning it off enables Auto Config, allowing the Pixel to automatically send page metadata and button interactions to improve ad delivery and reporting.",
|
|
38
37
|
label: 'Disable Auto Config',
|
|
39
38
|
type: 'boolean',
|
|
40
39
|
default: true
|
|
41
40
|
},
|
|
42
41
|
disableFirstPartyCookies: {
|
|
43
|
-
description:
|
|
44
|
-
'Control whether Facebook’s Meta Pixel uses first-party cookies. When this toggle is on, first-party cookies are disabled, enhancing user privacy. Turning it off enables the use of first-party cookies for more accurate tracking.',
|
|
42
|
+
description: "Control whether Facebook’s Meta Pixel uses first-party cookies. When this toggle is on, first-party cookies are disabled, enhancing user privacy. Turning it off enables the use of first-party cookies for more accurate tracking.",
|
|
45
43
|
label: 'Disable First Party Cookies',
|
|
46
44
|
type: 'boolean',
|
|
47
45
|
default: false
|
|
@@ -58,8 +56,8 @@ export const destination: BrowserDestinationDefinition<Settings, FBClient> = {
|
|
|
58
56
|
type: 'string',
|
|
59
57
|
required: true,
|
|
60
58
|
choices: [
|
|
61
|
-
{ label: 'LDU disabled', value: LDU.Disabled.key
|
|
62
|
-
{ label:
|
|
59
|
+
{ label: 'LDU disabled', value: LDU.Disabled.key},
|
|
60
|
+
{ label: "LDU enabled - Use Meta Geolocation Logic", value: LDU.GeolocationLogic.key },
|
|
63
61
|
{ label: 'LDU enabled - California only', value: LDU.California.key },
|
|
64
62
|
{ label: 'LDU enabled - Colorado only', value: LDU.Colorado.key },
|
|
65
63
|
{ label: 'LDU enabled - Connecticut only', value: LDU.Connecticut.key },
|
|
@@ -74,14 +72,25 @@ export const destination: BrowserDestinationDefinition<Settings, FBClient> = {
|
|
|
74
72
|
{ label: 'LDU enabled - Minnesota only', value: LDU.Minnesota.key }
|
|
75
73
|
],
|
|
76
74
|
default: LDU.Disabled.key
|
|
75
|
+
},
|
|
76
|
+
formatUserDataWithParamBuilder: {
|
|
77
|
+
description: 'If enabled, uses Facebook’s Parameter Builder library to help ensure that User Data values are properly formatted before being sent to Facebook.',
|
|
78
|
+
label: 'Format User Data with Parameter Builder',
|
|
79
|
+
type: 'boolean',
|
|
80
|
+
default: true
|
|
77
81
|
}
|
|
78
82
|
},
|
|
79
83
|
initialize: async ({ settings, analytics }, deps) => {
|
|
84
|
+
const { formatUserDataWithParamBuilder } = settings
|
|
80
85
|
initScript(settings, analytics)
|
|
81
86
|
await deps.resolveWhen(() => typeof window.fbq === 'function', 100)
|
|
82
|
-
|
|
87
|
+
if(formatUserDataWithParamBuilder){
|
|
88
|
+
const script = `https://capi-automation.s3.us-east-2.amazonaws.com/public/client_js/capiParamBuilder/clientParamBuilder.bundle.js`
|
|
89
|
+
await deps.loadScript(script)
|
|
90
|
+
await deps.resolveWhen(() => typeof window.clientParamBuilder === 'object', 100)
|
|
91
|
+
}
|
|
92
|
+
return { fbq: window.fbq, clientParamBuilder: window.clientParamBuilder || undefined }
|
|
83
93
|
},
|
|
84
|
-
|
|
85
94
|
actions: {
|
|
86
95
|
send
|
|
87
96
|
},
|
|
@@ -90,7 +99,8 @@ export const destination: BrowserDestinationDefinition<Settings, FBClient> = {
|
|
|
90
99
|
name: 'AddPaymentInfo',
|
|
91
100
|
subscribe: 'event = "Payment Info Entered"',
|
|
92
101
|
partnerAction: 'send',
|
|
93
|
-
mapping:
|
|
102
|
+
mapping:
|
|
103
|
+
{
|
|
94
104
|
...defaultValues(send.fields),
|
|
95
105
|
event_config: {
|
|
96
106
|
event_name: 'AddPaymentInfo',
|
|
@@ -103,7 +113,8 @@ export const destination: BrowserDestinationDefinition<Settings, FBClient> = {
|
|
|
103
113
|
name: 'AddToCart',
|
|
104
114
|
subscribe: 'event = "Product Added"',
|
|
105
115
|
partnerAction: 'send',
|
|
106
|
-
mapping:
|
|
116
|
+
mapping:
|
|
117
|
+
{
|
|
107
118
|
...defaultValues(send.fields),
|
|
108
119
|
event_config: {
|
|
109
120
|
event_name: 'AddToCart',
|
|
@@ -118,12 +129,13 @@ export const destination: BrowserDestinationDefinition<Settings, FBClient> = {
|
|
|
118
129
|
value: { '@path': '$.properties.price' }
|
|
119
130
|
},
|
|
120
131
|
type: 'automatic'
|
|
121
|
-
},
|
|
132
|
+
},
|
|
122
133
|
{
|
|
123
134
|
name: 'AddToWishlist',
|
|
124
135
|
subscribe: 'event = "Product Added To Wishlist"',
|
|
125
136
|
partnerAction: 'send',
|
|
126
|
-
mapping:
|
|
137
|
+
mapping:
|
|
138
|
+
{
|
|
127
139
|
...defaultValues(send.fields),
|
|
128
140
|
event_config: {
|
|
129
141
|
event_name: 'AddToWishlist',
|
|
@@ -143,7 +155,8 @@ export const destination: BrowserDestinationDefinition<Settings, FBClient> = {
|
|
|
143
155
|
name: 'CompleteRegistration',
|
|
144
156
|
subscribe: 'event = "Signed Up"',
|
|
145
157
|
partnerAction: 'send',
|
|
146
|
-
mapping:
|
|
158
|
+
mapping:
|
|
159
|
+
{
|
|
147
160
|
...defaultValues(send.fields),
|
|
148
161
|
event_config: {
|
|
149
162
|
event_name: 'CompleteRegistration',
|
|
@@ -151,12 +164,13 @@ export const destination: BrowserDestinationDefinition<Settings, FBClient> = {
|
|
|
151
164
|
}
|
|
152
165
|
},
|
|
153
166
|
type: 'automatic'
|
|
154
|
-
},
|
|
167
|
+
},
|
|
155
168
|
{
|
|
156
169
|
name: 'InitiateCheckout',
|
|
157
170
|
subscribe: 'event = "Checkout Started"',
|
|
158
171
|
partnerAction: 'send',
|
|
159
|
-
mapping:
|
|
172
|
+
mapping:
|
|
173
|
+
{
|
|
160
174
|
...defaultValues(send.fields),
|
|
161
175
|
event_config: {
|
|
162
176
|
event_name: 'InitiateCheckout',
|
|
@@ -184,13 +198,14 @@ export const destination: BrowserDestinationDefinition<Settings, FBClient> = {
|
|
|
184
198
|
name: 'Purchase',
|
|
185
199
|
subscribe: 'event = "Order Completed"',
|
|
186
200
|
partnerAction: 'send',
|
|
187
|
-
mapping:
|
|
201
|
+
mapping:
|
|
202
|
+
{
|
|
188
203
|
...defaultValues(send.fields),
|
|
189
204
|
event_config: {
|
|
190
205
|
event_name: 'Purchase',
|
|
191
206
|
show_fields: false
|
|
192
207
|
},
|
|
193
|
-
value: { '@path': '$.properties.revenue' },
|
|
208
|
+
value: { '@path': '$.properties.revenue' },
|
|
194
209
|
custom_data: {
|
|
195
210
|
order_id: { '@path': '$.properties.order_id' }
|
|
196
211
|
}
|
|
@@ -201,7 +216,8 @@ export const destination: BrowserDestinationDefinition<Settings, FBClient> = {
|
|
|
201
216
|
name: 'Search',
|
|
202
217
|
subscribe: 'event = "Products Searched"',
|
|
203
218
|
partnerAction: 'send',
|
|
204
|
-
mapping:
|
|
219
|
+
mapping:
|
|
220
|
+
{
|
|
205
221
|
...defaultValues(send.fields),
|
|
206
222
|
event_config: {
|
|
207
223
|
event_name: 'Search',
|
|
@@ -220,7 +236,8 @@ export const destination: BrowserDestinationDefinition<Settings, FBClient> = {
|
|
|
220
236
|
name: 'ViewContent',
|
|
221
237
|
subscribe: 'event = "Product Viewed"',
|
|
222
238
|
partnerAction: 'send',
|
|
223
|
-
mapping:
|
|
239
|
+
mapping:
|
|
240
|
+
{
|
|
224
241
|
...defaultValues(send.fields),
|
|
225
242
|
event_config: {
|
|
226
243
|
event_name: 'ViewContent',
|
|
@@ -230,7 +247,7 @@ export const destination: BrowserDestinationDefinition<Settings, FBClient> = {
|
|
|
230
247
|
id: { '@path': '$.properties.product_id' },
|
|
231
248
|
quantity: { '@path': '$.properties.quantity' },
|
|
232
249
|
item_price: { '@path': '$.properties.price' }
|
|
233
|
-
},
|
|
250
|
+
},
|
|
234
251
|
content_ids: { '@path': '$.properties.product_id' },
|
|
235
252
|
value: { '@path': '$.properties.price' }
|
|
236
253
|
},
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { getDependenciesFor } from '../depends-on'
|
|
2
|
+
|
|
3
|
+
describe('depends-on getDependenciesFor', () => {
|
|
4
|
+
test('returns correct depends_on rules', () => {
|
|
5
|
+
const result = getDependenciesFor('delivery_category')
|
|
6
|
+
expect(true).toBe(true)
|
|
7
|
+
expect(result.match).toBe('any')
|
|
8
|
+
expect(result.conditions).toEqual(
|
|
9
|
+
[
|
|
10
|
+
{
|
|
11
|
+
fieldKey: 'event_config.show_fields',
|
|
12
|
+
operator: 'is',
|
|
13
|
+
value: 'true'
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
fieldKey: 'event_config.event_name',
|
|
17
|
+
operator: 'is',
|
|
18
|
+
value: 'Purchase'
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
fieldKey: 'event_config.event_name',
|
|
22
|
+
operator: 'is',
|
|
23
|
+
value: 'InitiateCheckout'
|
|
24
|
+
}
|
|
25
|
+
]
|
|
26
|
+
)
|
|
27
|
+
})
|
|
28
|
+
})
|