@segment/analytics-browser-actions-google-campaign-manager 1.1.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/README.md +31 -0
- package/dist/cjs/counterActivity/generated-types.d.ts +13 -0
- package/dist/cjs/counterActivity/generated-types.js +3 -0
- package/dist/cjs/counterActivity/generated-types.js.map +1 -0
- package/dist/cjs/counterActivity/index.d.ts +5 -0
- package/dist/cjs/counterActivity/index.js +68 -0
- package/dist/cjs/counterActivity/index.js.map +1 -0
- package/dist/cjs/generated-types.d.ts +5 -0
- package/dist/cjs/generated-types.js +3 -0
- package/dist/cjs/generated-types.js.map +1 -0
- package/dist/cjs/index.d.ts +11 -0
- package/dist/cjs/index.js +55 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/salesActivity/generated-types.d.ts +15 -0
- package/dist/cjs/salesActivity/generated-types.js +3 -0
- package/dist/cjs/salesActivity/generated-types.js.map +1 -0
- package/dist/cjs/salesActivity/index.d.ts +5 -0
- package/dist/cjs/salesActivity/index.js +90 -0
- package/dist/cjs/salesActivity/index.js.map +1 -0
- package/dist/cjs/types.d.ts +3 -0
- package/dist/cjs/types.js +3 -0
- package/dist/cjs/types.js.map +1 -0
- package/dist/esm/counterActivity/generated-types.d.ts +13 -0
- package/dist/esm/counterActivity/generated-types.js +2 -0
- package/dist/esm/counterActivity/generated-types.js.map +1 -0
- package/dist/esm/counterActivity/index.d.ts +5 -0
- package/dist/esm/counterActivity/index.js +66 -0
- package/dist/esm/counterActivity/index.js.map +1 -0
- package/dist/esm/generated-types.d.ts +5 -0
- package/dist/esm/generated-types.js +2 -0
- package/dist/esm/generated-types.js.map +1 -0
- package/dist/esm/index.d.ts +11 -0
- package/dist/esm/index.js +51 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/salesActivity/generated-types.d.ts +15 -0
- package/dist/esm/salesActivity/generated-types.js +2 -0
- package/dist/esm/salesActivity/generated-types.js.map +1 -0
- package/dist/esm/salesActivity/index.d.ts +5 -0
- package/dist/esm/salesActivity/index.js +88 -0
- package/dist/esm/salesActivity/index.js.map +1 -0
- package/dist/esm/types.d.ts +3 -0
- package/dist/esm/types.js +2 -0
- package/dist/esm/types.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -0
- package/package.json +25 -0
- package/src/__tests__/counterActivity.test.ts +131 -0
- package/src/__tests__/salesActivity.test.ts +107 -0
- package/src/counterActivity/generated-types.ts +36 -0
- package/src/counterActivity/index.ts +76 -0
- package/src/generated-types.ts +16 -0
- package/src/index.ts +69 -0
- package/src/salesActivity/generated-types.ts +49 -0
- package/src/salesActivity/index.ts +98 -0
- package/src/types.ts +3 -0
- package/tsconfig.json +9 -0
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import type { BrowserActionDefinition } from '@segment/browser-destination-runtime/types'
|
|
2
|
+
import type { Settings } from '../generated-types'
|
|
3
|
+
import type { Payload } from './generated-types'
|
|
4
|
+
|
|
5
|
+
const action: BrowserActionDefinition<Settings, Function, Payload> = {
|
|
6
|
+
title: 'Counter Activity',
|
|
7
|
+
description: 'Record non-monetary conversion data such as unique users, conversions, and session length.',
|
|
8
|
+
defaultSubscription: 'type = "track"',
|
|
9
|
+
platform: 'web',
|
|
10
|
+
fields: {
|
|
11
|
+
activityGroupTagString: {
|
|
12
|
+
label: 'Activity Group Tag String',
|
|
13
|
+
description:
|
|
14
|
+
'An identifier for the Floodlight activity group associated with this activity, which appears as a parameter in your tags. This value is case sensitive.',
|
|
15
|
+
type: 'string',
|
|
16
|
+
required: true
|
|
17
|
+
},
|
|
18
|
+
activityTagString: {
|
|
19
|
+
label: 'Activity Tag String',
|
|
20
|
+
description:
|
|
21
|
+
'An identifier for your Floodlight activity, which appears as a parameter in your tags. This value is case sensitive.',
|
|
22
|
+
type: 'string',
|
|
23
|
+
required: true
|
|
24
|
+
},
|
|
25
|
+
enableDynamicTags: {
|
|
26
|
+
label: 'Enable Dynamic Tags',
|
|
27
|
+
type: 'boolean',
|
|
28
|
+
description:
|
|
29
|
+
'In Campaign Manager, go to Floodlight -> Configuration, under Tags, if **Dynamic** is selected, select **True**.'
|
|
30
|
+
},
|
|
31
|
+
countingMethod: {
|
|
32
|
+
label: 'Counting Method',
|
|
33
|
+
type: 'string',
|
|
34
|
+
description: 'Specifies how conversions will be counted for this Floodlight activity.',
|
|
35
|
+
choices: [
|
|
36
|
+
{ value: 'standard', label: 'Standard' },
|
|
37
|
+
{ value: 'unique', label: 'Unique' },
|
|
38
|
+
{ value: 'per_session', label: 'Per Session' }
|
|
39
|
+
],
|
|
40
|
+
required: true
|
|
41
|
+
},
|
|
42
|
+
sessionId: {
|
|
43
|
+
label: 'Session ID',
|
|
44
|
+
description:
|
|
45
|
+
'Use this field to insert a unique session ID if you’re using counter tags with a per session counting methodology. The session ID tells Campaign Manager 360 to count only one event per session on your site.',
|
|
46
|
+
type: 'string'
|
|
47
|
+
},
|
|
48
|
+
uVariables: {
|
|
49
|
+
label: 'U Variables',
|
|
50
|
+
description:
|
|
51
|
+
'Custom Floodlight variables enable you to capture information beyond the basics (visits and revenue) that you can collect with standard parameters in your tags.',
|
|
52
|
+
type: 'object',
|
|
53
|
+
defaultObjectUI: 'keyvalue:only'
|
|
54
|
+
},
|
|
55
|
+
dcCustomParams: {
|
|
56
|
+
label: 'Custom Parameters',
|
|
57
|
+
description:
|
|
58
|
+
'You can insert custom data into event snippets with the dc_custom_params field. This field accepts any values you want to pass to Google Marketing Platform.',
|
|
59
|
+
type: 'object',
|
|
60
|
+
defaultObjectUI: 'keyvalue:only'
|
|
61
|
+
}
|
|
62
|
+
},
|
|
63
|
+
perform: (gtag, { payload, settings }) => {
|
|
64
|
+
const requestBody = {
|
|
65
|
+
allow_custom_scripts: payload.enableDynamicTags,
|
|
66
|
+
send_to: `${settings.advertiserId}/${payload.activityGroupTagString}/${payload.activityTagString}+${payload.countingMethod}`,
|
|
67
|
+
...(payload.sessionId !== undefined &&
|
|
68
|
+
payload.countingMethod == 'per_session' && { session_id: payload.sessionId }),
|
|
69
|
+
...payload.uVariables,
|
|
70
|
+
...(payload.dcCustomParams !== undefined && { dc_custom_params: { ...payload.dcCustomParams } })
|
|
71
|
+
}
|
|
72
|
+
gtag('event', 'conversion', requestBody)
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
export default action
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// Generated file. DO NOT MODIFY IT BY HAND.
|
|
2
|
+
|
|
3
|
+
export interface Settings {
|
|
4
|
+
/**
|
|
5
|
+
* In Campaign Manager, go to Floodlight -> Configuration, and Advertiser ID is located under the Configuration heading.
|
|
6
|
+
*/
|
|
7
|
+
advertiserId: string
|
|
8
|
+
/**
|
|
9
|
+
* This feature can be disabled if you do not want the global site tag to allow personalized remarketing data for site users.
|
|
10
|
+
*/
|
|
11
|
+
allowAdPersonalizationSignals: boolean
|
|
12
|
+
/**
|
|
13
|
+
* This feature can be disabled if you do not want the global site tag to set first party cookies on your site domain.
|
|
14
|
+
*/
|
|
15
|
+
conversionLinker: boolean
|
|
16
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import type { Settings } from './generated-types'
|
|
2
|
+
import type { BrowserDestinationDefinition } from '@segment/browser-destination-runtime/types'
|
|
3
|
+
import { browserDestination } from '@segment/browser-destination-runtime/shim'
|
|
4
|
+
import counterActivity from './counterActivity'
|
|
5
|
+
import salesActivity from './salesActivity'
|
|
6
|
+
|
|
7
|
+
declare global {
|
|
8
|
+
interface Window {
|
|
9
|
+
gtag: Function
|
|
10
|
+
dataLayer: any
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export const destination: BrowserDestinationDefinition<Settings, Function> = {
|
|
15
|
+
name: 'Google Tag for Campaign Manager',
|
|
16
|
+
slug: 'actions-google-campaign-manager',
|
|
17
|
+
mode: 'device',
|
|
18
|
+
|
|
19
|
+
settings: {
|
|
20
|
+
advertiserId: {
|
|
21
|
+
description:
|
|
22
|
+
'In Campaign Manager, go to Floodlight -> Configuration, and Advertiser ID is located under the Configuration heading.',
|
|
23
|
+
label: 'Advertiser ID',
|
|
24
|
+
type: 'string',
|
|
25
|
+
required: true,
|
|
26
|
+
default: 'DC-'
|
|
27
|
+
},
|
|
28
|
+
allowAdPersonalizationSignals: {
|
|
29
|
+
description:
|
|
30
|
+
'This feature can be disabled if you do not want the global site tag to allow personalized remarketing data for site users.',
|
|
31
|
+
label: 'Allow Ad Personalization Signals',
|
|
32
|
+
type: 'boolean',
|
|
33
|
+
required: true,
|
|
34
|
+
default: true
|
|
35
|
+
},
|
|
36
|
+
conversionLinker: {
|
|
37
|
+
description:
|
|
38
|
+
'This feature can be disabled if you do not want the global site tag to set first party cookies on your site domain.',
|
|
39
|
+
label: 'Conversion Linker',
|
|
40
|
+
type: 'boolean',
|
|
41
|
+
required: true,
|
|
42
|
+
default: true
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
|
|
46
|
+
initialize: async ({ settings }, deps) => {
|
|
47
|
+
window.dataLayer = window.dataLayer || []
|
|
48
|
+
window.gtag = function () {
|
|
49
|
+
// eslint-disable-next-line prefer-rest-params
|
|
50
|
+
window.dataLayer.push(arguments)
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
window.gtag('set', 'allow_ad_personalization_signals', settings.allowAdPersonalizationSignals)
|
|
54
|
+
window.gtag('js', new Date())
|
|
55
|
+
window.gtag('config', settings.advertiserId, {
|
|
56
|
+
conversion_linker: settings.conversionLinker
|
|
57
|
+
})
|
|
58
|
+
const script = `https://www.googletagmanager.com/gtag/js?id=${settings.advertiserId}`
|
|
59
|
+
await deps.loadScript(script)
|
|
60
|
+
return window.gtag
|
|
61
|
+
},
|
|
62
|
+
|
|
63
|
+
actions: {
|
|
64
|
+
counterActivity,
|
|
65
|
+
salesActivity
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export default browserDestination(destination)
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
// Generated file. DO NOT MODIFY IT BY HAND.
|
|
2
|
+
|
|
3
|
+
export interface Payload {
|
|
4
|
+
/**
|
|
5
|
+
* An identifier for the Floodlight activity group associated with this activity, which appears as a parameter in your tags. This value is case sensitive.
|
|
6
|
+
*/
|
|
7
|
+
activityGroupTagString: string
|
|
8
|
+
/**
|
|
9
|
+
* An identifier for your Floodlight activity, which appears as a parameter in your tags. This value is case sensitive.
|
|
10
|
+
*/
|
|
11
|
+
activityTagString: string
|
|
12
|
+
/**
|
|
13
|
+
* In Campaign Manager, go to Floodlight -> Configuration, under Tags, if **Dynamic** is selected, select **True**
|
|
14
|
+
*/
|
|
15
|
+
enableDynamicTags?: boolean
|
|
16
|
+
/**
|
|
17
|
+
* Specifies how conversions will be counted for this Floodlight activity.
|
|
18
|
+
*/
|
|
19
|
+
countingMethod: string
|
|
20
|
+
/**
|
|
21
|
+
* Use this field to insert a unique numerical identifier for each transaction. Can be alphanumeric.
|
|
22
|
+
*/
|
|
23
|
+
transactionId: string
|
|
24
|
+
/**
|
|
25
|
+
* Use this field to pass the revenue generated by a transaction. Typically the purchase price and value does not include taxes or shipping.
|
|
26
|
+
*/
|
|
27
|
+
value: string
|
|
28
|
+
/**
|
|
29
|
+
*
|
|
30
|
+
* Use this field to pass the number of items sold during a transaction:
|
|
31
|
+
* - If you're counting each transaction as a single conversion, the value is 1.
|
|
32
|
+
* - If you're counting each item sold during a single transaction as a separate conversion, insert the number of items sold as part of each transaction as the value.
|
|
33
|
+
* - The value must be an integer greater than zero.
|
|
34
|
+
*
|
|
35
|
+
*/
|
|
36
|
+
quantity: number
|
|
37
|
+
/**
|
|
38
|
+
* Custom Floodlight variables enable you to capture information beyond the basics (visits and revenue) that you can collect with standard parameters in your tags.
|
|
39
|
+
*/
|
|
40
|
+
uVariables?: {
|
|
41
|
+
[k: string]: unknown
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* You can insert custom data into event snippets with the dc_custom_params field. This field accepts any values you want to pass to Google Marketing Platform.
|
|
45
|
+
*/
|
|
46
|
+
dcCustomParams?: {
|
|
47
|
+
[k: string]: unknown
|
|
48
|
+
}
|
|
49
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import type { BrowserActionDefinition } from '@segment/browser-destination-runtime/types'
|
|
2
|
+
import type { Settings } from '../generated-types'
|
|
3
|
+
import type { Payload } from './generated-types'
|
|
4
|
+
|
|
5
|
+
const action: BrowserActionDefinition<Settings, Function, Payload> = {
|
|
6
|
+
title: 'Sales Activity',
|
|
7
|
+
description: 'Record monetary data for conversions, such as cost and the number of items sold.',
|
|
8
|
+
defaultSubscription: 'type = "track"',
|
|
9
|
+
platform: 'web',
|
|
10
|
+
fields: {
|
|
11
|
+
activityGroupTagString: {
|
|
12
|
+
label: 'Activity Group Tag String',
|
|
13
|
+
description:
|
|
14
|
+
'An identifier for the Floodlight activity group associated with this activity, which appears as a parameter in your tags. This value is case sensitive.',
|
|
15
|
+
type: 'string',
|
|
16
|
+
required: true
|
|
17
|
+
},
|
|
18
|
+
activityTagString: {
|
|
19
|
+
label: 'Activity Tag String',
|
|
20
|
+
description:
|
|
21
|
+
'An identifier for your Floodlight activity, which appears as a parameter in your tags. This value is case sensitive.',
|
|
22
|
+
type: 'string',
|
|
23
|
+
required: true
|
|
24
|
+
},
|
|
25
|
+
enableDynamicTags: {
|
|
26
|
+
label: 'Enable Dynamic Tags',
|
|
27
|
+
type: 'boolean',
|
|
28
|
+
description:
|
|
29
|
+
'In Campaign Manager, go to Floodlight -> Configuration, under Tags, if **Dynamic** is selected, select **True**.'
|
|
30
|
+
},
|
|
31
|
+
countingMethod: {
|
|
32
|
+
label: 'Counting Method',
|
|
33
|
+
type: 'string',
|
|
34
|
+
description: 'Specifies how conversions will be counted for this Floodlight activity.',
|
|
35
|
+
choices: [
|
|
36
|
+
{ value: 'transactions', label: 'Transactions' },
|
|
37
|
+
{ value: 'items_sold', label: 'Items Sold' }
|
|
38
|
+
],
|
|
39
|
+
required: true
|
|
40
|
+
},
|
|
41
|
+
transactionId: {
|
|
42
|
+
label: 'Transaction ID',
|
|
43
|
+
description: 'Use this field to insert a unique numerical identifier for each transaction. Can be alphanumeric.',
|
|
44
|
+
type: 'string',
|
|
45
|
+
required: true,
|
|
46
|
+
default: {
|
|
47
|
+
'@path': '$.properties.order_id'
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
value: {
|
|
51
|
+
label: 'Value',
|
|
52
|
+
description:
|
|
53
|
+
'Use this field to pass the revenue generated by a transaction. Typically the purchase price and value does not include taxes or shipping.',
|
|
54
|
+
type: 'string',
|
|
55
|
+
required: true,
|
|
56
|
+
default: { '@path': '$.properties.total' }
|
|
57
|
+
},
|
|
58
|
+
quantity: {
|
|
59
|
+
label: 'Quantity',
|
|
60
|
+
description: `
|
|
61
|
+
Use this field to pass the number of items sold during a transaction:
|
|
62
|
+
- If you're counting each transaction as a single conversion, the value is 1.
|
|
63
|
+
- If you're counting each item sold during a single transaction as a separate conversion, insert the number of items sold as part of each transaction as the value.
|
|
64
|
+
- The value must be an integer greater than zero.
|
|
65
|
+
`,
|
|
66
|
+
type: 'integer',
|
|
67
|
+
required: true
|
|
68
|
+
},
|
|
69
|
+
uVariables: {
|
|
70
|
+
label: 'U Variables',
|
|
71
|
+
description:
|
|
72
|
+
'Custom Floodlight variables enable you to capture information beyond the basics (visits and revenue) that you can collect with standard parameters in your tags.',
|
|
73
|
+
type: 'object',
|
|
74
|
+
defaultObjectUI: 'keyvalue:only'
|
|
75
|
+
},
|
|
76
|
+
dcCustomParams: {
|
|
77
|
+
label: 'Custom Parameters',
|
|
78
|
+
description:
|
|
79
|
+
'You can insert custom data into event snippets with the dc_custom_params field. This field accepts any values you want to pass to Google Marketing Platform.',
|
|
80
|
+
type: 'object',
|
|
81
|
+
defaultObjectUI: 'keyvalue:only'
|
|
82
|
+
}
|
|
83
|
+
},
|
|
84
|
+
perform: (gtag, { payload, settings }) => {
|
|
85
|
+
const requestBody = {
|
|
86
|
+
allow_custom_scripts: payload.enableDynamicTags,
|
|
87
|
+
send_to: `${settings.advertiserId}/${payload.activityGroupTagString}/${payload.activityTagString}+${payload.countingMethod}`,
|
|
88
|
+
value: payload.value,
|
|
89
|
+
transaction_id: payload.transactionId,
|
|
90
|
+
quantity: payload.quantity,
|
|
91
|
+
...payload.uVariables,
|
|
92
|
+
...(payload.dcCustomParams !== undefined && { dc_custom_params: { ...payload.dcCustomParams } })
|
|
93
|
+
}
|
|
94
|
+
gtag('event', 'purchase', requestBody)
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export default action
|
package/src/types.ts
ADDED