@segment/analytics-browser-actions-facebook-conversions-api-web 1.9.0 → 1.9.1-staging-c01044061.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.js +5 -2
- package/dist/cjs/functions.js.map +1 -1
- package/dist/cjs/index.js +4 -4
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/send/depends-on.js +35 -3
- package/dist/cjs/send/depends-on.js.map +1 -1
- package/dist/cjs/send/fields.js +4 -4
- package/dist/cjs/send/fields.js.map +1 -1
- package/dist/cjs/send/functions.js +9 -7
- package/dist/cjs/send/functions.js.map +1 -1
- package/dist/cjs/types.js.map +1 -1
- package/dist/esm/functions.js +5 -2
- package/dist/esm/functions.js.map +1 -1
- package/dist/esm/index.js +4 -4
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/send/depends-on.js +35 -3
- package/dist/esm/send/depends-on.js.map +1 -1
- package/dist/esm/send/fields.js +4 -4
- package/dist/esm/send/fields.js.map +1 -1
- package/dist/esm/send/functions.js +9 -7
- package/dist/esm/send/functions.js.map +1 -1
- package/dist/esm/types.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +3 -3
- package/src/constants.ts +1 -1
- package/src/functions.ts +59 -66
- package/src/index.ts +22 -27
- package/src/send/depends-on.ts +62 -30
- package/src/send/fields.ts +299 -291
- package/src/send/functions.ts +151 -179
- package/src/send/index.ts +2 -2
- package/src/types.ts +21 -21
package/src/functions.ts
CHANGED
|
@@ -1,64 +1,52 @@
|
|
|
1
|
-
import { WindowWithOptionalFbq, InitOptions, LDU, UserData, FBClient} from './types'
|
|
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} from './constants'
|
|
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
|
-
|
|
17
|
-
f: WindowWithOptionalFbq,
|
|
18
|
-
b: Document,
|
|
19
|
-
e: 'script',
|
|
20
|
-
v: string,
|
|
21
|
-
n: FBClient | undefined = undefined,
|
|
22
|
-
t: HTMLScriptElement | undefined = undefined,
|
|
7
|
+
const { pixelId, disablePushState, disableAutoConfig, disableFirstPartyCookies, agent, ldu } =
|
|
8
|
+
settings as Settings & { ldu: keyof typeof LDU }
|
|
9
|
+
|
|
10
|
+
;(function (
|
|
11
|
+
f: WindowWithOptionalFbq,
|
|
12
|
+
b: Document,
|
|
13
|
+
e: 'script',
|
|
14
|
+
v: string,
|
|
15
|
+
n: FBClient | undefined = undefined,
|
|
16
|
+
t: HTMLScriptElement | undefined = undefined,
|
|
23
17
|
s: Element | null = null
|
|
24
|
-
){
|
|
25
|
-
if (f.fbq) return
|
|
26
|
-
n = f.fbq = function() {
|
|
18
|
+
) {
|
|
19
|
+
if (f.fbq) return
|
|
20
|
+
n = f.fbq = function () {
|
|
27
21
|
/* eslint-disable */
|
|
28
22
|
// @ts-expect-error - n is defined by the time this executes
|
|
29
|
-
n.callMethod ? n.callMethod.apply(n, arguments) : n.queue.push(arguments)
|
|
23
|
+
n.callMethod ? n.callMethod.apply(n, arguments) : n.queue.push(arguments)
|
|
30
24
|
/* eslint-enable */
|
|
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]
|
|
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]
|
|
41
35
|
if (s && s.parentNode) {
|
|
42
|
-
s.parentNode.insertBefore(t, s)
|
|
36
|
+
s.parentNode.insertBefore(t, s)
|
|
43
37
|
}
|
|
44
|
-
})(
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
'script',
|
|
48
|
-
'https://connect.facebook.net/en_US/fbevents.js'
|
|
49
|
-
);
|
|
50
|
-
|
|
51
|
-
if(ldu === LDU.Disabled.key) {
|
|
38
|
+
})(window, document, 'script', 'https://connect.facebook.net/en_US/fbevents.js')
|
|
39
|
+
|
|
40
|
+
if (ldu === LDU.Disabled.key) {
|
|
52
41
|
window.fbq('dataProcessingOptions', [])
|
|
53
|
-
}
|
|
54
|
-
else {
|
|
42
|
+
} else {
|
|
55
43
|
const lduObj = getLDU(ldu)
|
|
56
44
|
window.fbq('dataProcessingOptions', ['LDU'], lduObj.country, lduObj.state)
|
|
57
45
|
}
|
|
58
46
|
|
|
59
|
-
if(disablePushState) {
|
|
47
|
+
if (disablePushState) {
|
|
60
48
|
window.fbq.disablePushState = true
|
|
61
|
-
}
|
|
49
|
+
}
|
|
62
50
|
|
|
63
51
|
if (disableAutoConfig) {
|
|
64
52
|
window.fbq('set', 'autoConfig', false, pixelId)
|
|
@@ -69,13 +57,13 @@ export function initScript(settings: Settings, analytics: Analytics) {
|
|
|
69
57
|
}
|
|
70
58
|
|
|
71
59
|
const userData = getStoredUserData(analytics)
|
|
72
|
-
const options: InitOptions | undefined =
|
|
60
|
+
const options: InitOptions | undefined = agent ? { agent } : undefined
|
|
73
61
|
const initArgs: [string, UserData?, InitOptions?] = [pixelId]
|
|
74
62
|
|
|
75
63
|
if (userData && Object.keys(userData).length > 0) {
|
|
76
|
-
initArgs.push(userData)
|
|
64
|
+
initArgs.push(userData)
|
|
77
65
|
if (options) {
|
|
78
|
-
initArgs.push(options)
|
|
66
|
+
initArgs.push(options)
|
|
79
67
|
}
|
|
80
68
|
} else if (options) {
|
|
81
69
|
initArgs.push(undefined, options)
|
|
@@ -86,7 +74,7 @@ export function initScript(settings: Settings, analytics: Analytics) {
|
|
|
86
74
|
setStorageInitCount(analytics, 1)
|
|
87
75
|
deleteStorageUserData(analytics)
|
|
88
76
|
|
|
89
|
-
if(!disablePushState) {
|
|
77
|
+
if (!disablePushState) {
|
|
90
78
|
window.fbq('trackSingle', pixelId, 'PageView')
|
|
91
79
|
}
|
|
92
80
|
}
|
|
@@ -118,24 +106,29 @@ export function deleteStorageUserData(analytics: Analytics) {
|
|
|
118
106
|
storage.set(USER_DATA_KEY, '')
|
|
119
107
|
}
|
|
120
108
|
|
|
121
|
-
function getStoredUserData(analytics: Analytics): UserData | undefined {
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
109
|
+
function getStoredUserData(analytics: Analytics): UserData | undefined {
|
|
110
|
+
const storage = (analytics.storage as UniversalStorage<Record<string, string>>) ?? storageFallback
|
|
111
|
+
const userDataFromStorage: string | null = storage.get(USER_DATA_KEY)
|
|
112
|
+
if (userDataFromStorage) {
|
|
113
|
+
try {
|
|
114
|
+
const parsed = JSON.parse(userDataFromStorage)
|
|
115
|
+
if (
|
|
116
|
+
!parsed ||
|
|
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
|
|
134
126
|
}
|
|
135
|
-
|
|
127
|
+
}
|
|
128
|
+
return undefined
|
|
136
129
|
}
|
|
137
130
|
|
|
138
131
|
function getLDU(ldu: keyof typeof LDU) {
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
}
|
|
132
|
+
const lduObj = LDU[ldu]
|
|
133
|
+
return { country: lduObj.country, state: lduObj.state }
|
|
134
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -8,7 +8,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
13
|
}
|
|
14
14
|
}
|
|
@@ -23,22 +23,25 @@ export const destination: BrowserDestinationDefinition<Settings, FBClient> = {
|
|
|
23
23
|
description: 'The Pixel ID associated with your Facebook Pixel.',
|
|
24
24
|
label: 'Pixel ID',
|
|
25
25
|
type: 'string',
|
|
26
|
-
required: true
|
|
26
|
+
required: true
|
|
27
27
|
},
|
|
28
28
|
disablePushState: {
|
|
29
|
-
description:
|
|
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
31
|
label: 'Disable Push State',
|
|
31
32
|
type: 'boolean',
|
|
32
33
|
default: false
|
|
33
34
|
},
|
|
34
35
|
disableAutoConfig: {
|
|
35
|
-
description:
|
|
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
38
|
label: 'Disable Auto Config',
|
|
37
39
|
type: 'boolean',
|
|
38
40
|
default: true
|
|
39
41
|
},
|
|
40
42
|
disableFirstPartyCookies: {
|
|
41
|
-
description:
|
|
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
45
|
label: 'Disable First Party Cookies',
|
|
43
46
|
type: 'boolean',
|
|
44
47
|
default: false
|
|
@@ -55,8 +58,8 @@ export const destination: BrowserDestinationDefinition<Settings, FBClient> = {
|
|
|
55
58
|
type: 'string',
|
|
56
59
|
required: true,
|
|
57
60
|
choices: [
|
|
58
|
-
{ label: 'LDU disabled', value: LDU.Disabled.key},
|
|
59
|
-
{ label:
|
|
61
|
+
{ label: 'LDU disabled', value: LDU.Disabled.key },
|
|
62
|
+
{ label: 'LDU enabled - Use Meta Geolocation Logic', value: LDU.GeolocationLogic.key },
|
|
60
63
|
{ label: 'LDU enabled - California only', value: LDU.California.key },
|
|
61
64
|
{ label: 'LDU enabled - Colorado only', value: LDU.Colorado.key },
|
|
62
65
|
{ label: 'LDU enabled - Connecticut only', value: LDU.Connecticut.key },
|
|
@@ -87,8 +90,7 @@ export const destination: BrowserDestinationDefinition<Settings, FBClient> = {
|
|
|
87
90
|
name: 'AddPaymentInfo',
|
|
88
91
|
subscribe: 'event = "Payment Info Entered"',
|
|
89
92
|
partnerAction: 'send',
|
|
90
|
-
mapping:
|
|
91
|
-
{
|
|
93
|
+
mapping: {
|
|
92
94
|
...defaultValues(send.fields),
|
|
93
95
|
event_config: {
|
|
94
96
|
event_name: 'AddPaymentInfo',
|
|
@@ -101,8 +103,7 @@ export const destination: BrowserDestinationDefinition<Settings, FBClient> = {
|
|
|
101
103
|
name: 'AddToCart',
|
|
102
104
|
subscribe: 'event = "Product Added"',
|
|
103
105
|
partnerAction: 'send',
|
|
104
|
-
mapping:
|
|
105
|
-
{
|
|
106
|
+
mapping: {
|
|
106
107
|
...defaultValues(send.fields),
|
|
107
108
|
event_config: {
|
|
108
109
|
event_name: 'AddToCart',
|
|
@@ -117,13 +118,12 @@ export const destination: BrowserDestinationDefinition<Settings, FBClient> = {
|
|
|
117
118
|
value: { '@path': '$.properties.price' }
|
|
118
119
|
},
|
|
119
120
|
type: 'automatic'
|
|
120
|
-
},
|
|
121
|
+
},
|
|
121
122
|
{
|
|
122
123
|
name: 'AddToWishlist',
|
|
123
124
|
subscribe: 'event = "Product Added To Wishlist"',
|
|
124
125
|
partnerAction: 'send',
|
|
125
|
-
mapping:
|
|
126
|
-
{
|
|
126
|
+
mapping: {
|
|
127
127
|
...defaultValues(send.fields),
|
|
128
128
|
event_config: {
|
|
129
129
|
event_name: 'AddToWishlist',
|
|
@@ -143,8 +143,7 @@ export const destination: BrowserDestinationDefinition<Settings, FBClient> = {
|
|
|
143
143
|
name: 'CompleteRegistration',
|
|
144
144
|
subscribe: 'event = "Signed Up"',
|
|
145
145
|
partnerAction: 'send',
|
|
146
|
-
mapping:
|
|
147
|
-
{
|
|
146
|
+
mapping: {
|
|
148
147
|
...defaultValues(send.fields),
|
|
149
148
|
event_config: {
|
|
150
149
|
event_name: 'CompleteRegistration',
|
|
@@ -152,13 +151,12 @@ export const destination: BrowserDestinationDefinition<Settings, FBClient> = {
|
|
|
152
151
|
}
|
|
153
152
|
},
|
|
154
153
|
type: 'automatic'
|
|
155
|
-
},
|
|
154
|
+
},
|
|
156
155
|
{
|
|
157
156
|
name: 'InitiateCheckout',
|
|
158
157
|
subscribe: 'event = "Checkout Started"',
|
|
159
158
|
partnerAction: 'send',
|
|
160
|
-
mapping:
|
|
161
|
-
{
|
|
159
|
+
mapping: {
|
|
162
160
|
...defaultValues(send.fields),
|
|
163
161
|
event_config: {
|
|
164
162
|
event_name: 'InitiateCheckout',
|
|
@@ -186,14 +184,13 @@ export const destination: BrowserDestinationDefinition<Settings, FBClient> = {
|
|
|
186
184
|
name: 'Purchase',
|
|
187
185
|
subscribe: 'event = "Order Completed"',
|
|
188
186
|
partnerAction: 'send',
|
|
189
|
-
mapping:
|
|
190
|
-
{
|
|
187
|
+
mapping: {
|
|
191
188
|
...defaultValues(send.fields),
|
|
192
189
|
event_config: {
|
|
193
190
|
event_name: 'Purchase',
|
|
194
191
|
show_fields: false
|
|
195
192
|
},
|
|
196
|
-
value: { '@path': '$.properties.revenue' },
|
|
193
|
+
value: { '@path': '$.properties.revenue' },
|
|
197
194
|
custom_data: {
|
|
198
195
|
order_id: { '@path': '$.properties.order_id' }
|
|
199
196
|
}
|
|
@@ -204,8 +201,7 @@ export const destination: BrowserDestinationDefinition<Settings, FBClient> = {
|
|
|
204
201
|
name: 'Search',
|
|
205
202
|
subscribe: 'event = "Products Searched"',
|
|
206
203
|
partnerAction: 'send',
|
|
207
|
-
mapping:
|
|
208
|
-
{
|
|
204
|
+
mapping: {
|
|
209
205
|
...defaultValues(send.fields),
|
|
210
206
|
event_config: {
|
|
211
207
|
event_name: 'Search',
|
|
@@ -224,8 +220,7 @@ export const destination: BrowserDestinationDefinition<Settings, FBClient> = {
|
|
|
224
220
|
name: 'ViewContent',
|
|
225
221
|
subscribe: 'event = "Product Viewed"',
|
|
226
222
|
partnerAction: 'send',
|
|
227
|
-
mapping:
|
|
228
|
-
{
|
|
223
|
+
mapping: {
|
|
229
224
|
...defaultValues(send.fields),
|
|
230
225
|
event_config: {
|
|
231
226
|
event_name: 'ViewContent',
|
|
@@ -235,7 +230,7 @@ export const destination: BrowserDestinationDefinition<Settings, FBClient> = {
|
|
|
235
230
|
id: { '@path': '$.properties.product_id' },
|
|
236
231
|
quantity: { '@path': '$.properties.quantity' },
|
|
237
232
|
item_price: { '@path': '$.properties.price' }
|
|
238
|
-
},
|
|
233
|
+
},
|
|
239
234
|
content_ids: { '@path': '$.properties.product_id' },
|
|
240
235
|
value: { '@path': '$.properties.price' }
|
|
241
236
|
},
|
package/src/send/depends-on.ts
CHANGED
|
@@ -2,47 +2,79 @@ import { DependsOnConditions, Condition } from '@segment/actions-core/destinatio
|
|
|
2
2
|
import type { FBStandardEventType, FBNonStandardEventType } from '../types'
|
|
3
3
|
|
|
4
4
|
export const fieldDependencies: Record<string, (FBStandardEventType | FBNonStandardEventType)[]> = {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
5
|
+
custom_event_name: ['CustomEvent'],
|
|
6
|
+
content_category: ['PageView', 'ViewContent', 'Search'],
|
|
7
|
+
content_ids: [
|
|
8
|
+
'AddPaymentInfo',
|
|
9
|
+
'AddToCart',
|
|
10
|
+
'AddToWishlist',
|
|
11
|
+
'InitiateCheckout',
|
|
12
|
+
'Purchase',
|
|
13
|
+
'Search',
|
|
14
|
+
'ViewContent'
|
|
15
|
+
],
|
|
16
|
+
content_name: ['PageView', 'ViewContent', 'Search'],
|
|
17
|
+
content_type: ['AddToCart', 'Purchase', 'Search', 'ViewContent'],
|
|
18
|
+
contents: ['AddPaymentInfo', 'AddToCart', 'AddToWishlist', 'InitiateCheckout', 'Purchase', 'Search', 'ViewContent'],
|
|
19
|
+
currency: [
|
|
20
|
+
'AddPaymentInfo',
|
|
21
|
+
'AddToCart',
|
|
22
|
+
'AddToWishlist',
|
|
23
|
+
'CompleteRegistration',
|
|
24
|
+
'InitiateCheckout',
|
|
25
|
+
'Lead',
|
|
26
|
+
'Purchase',
|
|
27
|
+
'Search',
|
|
28
|
+
'StartTrial',
|
|
29
|
+
'Subscribe',
|
|
30
|
+
'ViewContent'
|
|
31
|
+
],
|
|
32
|
+
delivery_category: ['Purchase', 'InitiateCheckout'],
|
|
33
|
+
num_items: ['InitiateCheckout'],
|
|
34
|
+
predicted_ltv: ['Purchase', 'Subscribe', 'StartTrial', 'CompleteRegistration', 'AddPaymentInfo', 'CustomEvent'],
|
|
35
|
+
net_revenue: ['Purchase'],
|
|
36
|
+
search_string: ['Search'],
|
|
37
|
+
status: ['CompleteRegistration'],
|
|
38
|
+
value: [
|
|
39
|
+
'AddPaymentInfo',
|
|
40
|
+
'AddToCart',
|
|
41
|
+
'AddToWishlist',
|
|
42
|
+
'CompleteRegistration',
|
|
43
|
+
'InitiateCheckout',
|
|
44
|
+
'Lead',
|
|
45
|
+
'Purchase',
|
|
46
|
+
'Search',
|
|
47
|
+
'StartTrial',
|
|
48
|
+
'Subscribe',
|
|
49
|
+
'ViewContent'
|
|
50
|
+
]
|
|
19
51
|
}
|
|
20
52
|
|
|
21
53
|
export function getDependenciesFor(fieldName: string): DependsOnConditions {
|
|
22
54
|
const conditions: Condition[] = [
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
55
|
+
{
|
|
56
|
+
fieldKey: 'event_config.show_fields',
|
|
57
|
+
operator: 'is',
|
|
58
|
+
value: 'true'
|
|
59
|
+
}
|
|
28
60
|
]
|
|
29
61
|
|
|
30
62
|
if (fieldDependencies[fieldName]) {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
63
|
+
conditions.push({
|
|
64
|
+
fieldKey: 'event_config.event_name',
|
|
65
|
+
operator: 'is',
|
|
66
|
+
value: fieldDependencies[fieldName]
|
|
67
|
+
})
|
|
36
68
|
}
|
|
37
69
|
|
|
38
70
|
return {
|
|
39
|
-
|
|
40
|
-
|
|
71
|
+
match: 'any',
|
|
72
|
+
conditions
|
|
41
73
|
}
|
|
42
74
|
}
|
|
43
75
|
|
|
44
76
|
export function getNotVisibleForEvent(event: FBStandardEventType | FBNonStandardEventType): string[] {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
}
|
|
77
|
+
return Object.entries(fieldDependencies)
|
|
78
|
+
.filter(([_, events]) => !events.includes(event))
|
|
79
|
+
.map(([fieldName]) => fieldName)
|
|
80
|
+
}
|