@mparticle/web-adwords-kit 2.1.1 → 2.2.1
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.
|
@@ -27,8 +27,8 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
27
27
|
CrashReport: 5,
|
|
28
28
|
OptOut: 6,
|
|
29
29
|
Commerce: 16
|
|
30
|
-
}
|
|
31
|
-
|
|
30
|
+
},
|
|
31
|
+
ENHANCED_CONVERSION_DATA = "GoogleAds.ECData";
|
|
32
32
|
|
|
33
33
|
var constructor = function () {
|
|
34
34
|
var self = this,
|
|
@@ -55,6 +55,17 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
55
55
|
|
|
56
56
|
try {
|
|
57
57
|
if (window.gtag && forwarderSettings.enableGtag == 'True') {
|
|
58
|
+
if (
|
|
59
|
+
forwarderSettings.enableEnhancedConversions ===
|
|
60
|
+
'True' &&
|
|
61
|
+
hasEnhancedConversionData(event.CustomFlags)
|
|
62
|
+
) {
|
|
63
|
+
window.enhanced_conversion_data =
|
|
64
|
+
parseEnhancedConversionData(
|
|
65
|
+
event.CustomFlags[ENHANCED_CONVERSION_DATA]
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
|
|
58
69
|
sendEventFunction = sendGtagEvent;
|
|
59
70
|
generateEventFunction = generateGtagEvent;
|
|
60
71
|
generateCommerceEvent = generateGtagCommerceEvent;
|
|
@@ -98,8 +109,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
98
109
|
}
|
|
99
110
|
|
|
100
111
|
return 'Can\'t send to forwarder: ' + name + '. Event not mapped';
|
|
101
|
-
}
|
|
102
|
-
catch (e) {
|
|
112
|
+
} catch (e) {
|
|
103
113
|
console.error('Can\t send to forwarder', e);
|
|
104
114
|
return 'Can\'t send to forwarder: ' + name + ' ' + e;
|
|
105
115
|
}
|
|
@@ -113,6 +123,31 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
113
123
|
return 'Can\'t send to forwarder ' + name + ', not initialized. Event added to queue.';
|
|
114
124
|
}
|
|
115
125
|
|
|
126
|
+
function hasEnhancedConversionData(customFlags) {
|
|
127
|
+
return customFlags && Object.keys(customFlags).length && customFlags[ENHANCED_CONVERSION_DATA];
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
function parseEnhancedConversionData(conversionData) {
|
|
131
|
+
// Checks if conversion data in custom flags is a stringified object
|
|
132
|
+
// Conversion data should only be a stringified object or a JS object
|
|
133
|
+
if (typeof conversionData === 'string') {
|
|
134
|
+
try {
|
|
135
|
+
return JSON.parse(conversionData);
|
|
136
|
+
} catch (error) {
|
|
137
|
+
console.warn('Unrecognized Enhanced Conversion Data Format', conversionData, error);
|
|
138
|
+
return {};
|
|
139
|
+
}
|
|
140
|
+
} else if (typeof conversionData === 'object') {
|
|
141
|
+
// Not a stringified object so it can be used as-is. However,
|
|
142
|
+
// we want to avoid mutating the original state, so we make a copy.
|
|
143
|
+
return cloneObject(conversionData);
|
|
144
|
+
} else {
|
|
145
|
+
console.warn('Unrecognized Enhanced Conversion Data Format', conversionData);
|
|
146
|
+
return {};
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
}
|
|
150
|
+
|
|
116
151
|
// Converts an mParticle Commerce Event into either Legacy or gtag Event
|
|
117
152
|
function generateCommerceEvent(mPEvent, conversionLabel, isPageEvent) {
|
|
118
153
|
if (mPEvent.ProductAction
|
|
@@ -135,7 +170,6 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
135
170
|
|
|
136
171
|
|
|
137
172
|
// ** Adwords Events
|
|
138
|
-
|
|
139
173
|
function getBaseAdWordEvent() {
|
|
140
174
|
var adWordEvent = {};
|
|
141
175
|
adWordEvent.google_conversion_value = 0;
|
|
@@ -189,6 +223,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
189
223
|
function generateGtagEvent(mPEvent, conversionLabel, customProps) {
|
|
190
224
|
if (!conversionLabel) { return null; }
|
|
191
225
|
var conversionPayload = getBaseGtagEvent(conversionLabel);
|
|
226
|
+
conversionPayload.transaction_id = mPEvent.SourceMessageId;
|
|
192
227
|
return mergeObjects(conversionPayload, customProps);
|
|
193
228
|
}
|
|
194
229
|
|
|
@@ -198,7 +233,9 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
198
233
|
|
|
199
234
|
if (mPEvent.ProductAction.ProductActionType === mParticle.ProductActionType.Purchase
|
|
200
235
|
&& mPEvent.ProductAction.TransactionId) {
|
|
201
|
-
conversionPayload.
|
|
236
|
+
conversionPayload.transaction_id = mPEvent.ProductAction.TransactionId;
|
|
237
|
+
} else {
|
|
238
|
+
conversionPayload.transaction_id = mPEvent.SourceMessageId;
|
|
202
239
|
}
|
|
203
240
|
|
|
204
241
|
if (mPEvent.CurrencyCode) {
|
|
@@ -300,7 +337,13 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
300
337
|
gTagScript.async = true;
|
|
301
338
|
gTagScript.onload = function () {
|
|
302
339
|
gtag('js', new Date());
|
|
303
|
-
|
|
340
|
+
if (forwarderSettings.enableEnhancedConversions === 'True') {
|
|
341
|
+
gtag('config', gtagSiteId, {
|
|
342
|
+
allow_enhanced_conversions: true
|
|
343
|
+
});
|
|
344
|
+
} else {
|
|
345
|
+
gtag('config', gtagSiteId);
|
|
346
|
+
}
|
|
304
347
|
isInitialized = true;
|
|
305
348
|
processQueue(eventQueue);
|
|
306
349
|
};
|
|
@@ -324,7 +367,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
324
367
|
}
|
|
325
368
|
|
|
326
369
|
function initForwarder(settings, service, testMode) {
|
|
327
|
-
|
|
370
|
+
window.enhanced_conversion_data = {};
|
|
328
371
|
forwarderSettings = settings;
|
|
329
372
|
reportingService = service;
|
|
330
373
|
|
|
@@ -435,6 +478,10 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
435
478
|
return resObj;
|
|
436
479
|
}
|
|
437
480
|
|
|
481
|
+
function cloneObject(obj) {
|
|
482
|
+
return JSON.parse(JSON.stringify(obj));
|
|
483
|
+
}
|
|
484
|
+
|
|
438
485
|
if (typeof window !== 'undefined') {
|
|
439
486
|
if (window && window.mParticle && window.mParticle.addForwarder) {
|
|
440
487
|
window.mParticle.addForwarder({
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mparticle/web-adwords-kit",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.2.1",
|
|
4
4
|
"author": "mParticle Developers <developers@mparticle.com> (https://www.mparticle.com)",
|
|
5
5
|
"description": "mParticle integration sdk for Google Adwords",
|
|
6
6
|
"main": "dist/GoogleAdWordsEventForwarder.common.js",
|
|
@@ -11,8 +11,9 @@
|
|
|
11
11
|
"repository": "https://github.com/mparticle-integrations/mparticle-javascript-integration-adwords",
|
|
12
12
|
"scripts": {
|
|
13
13
|
"build": "rollup --config rollup.config.js",
|
|
14
|
+
"build:test": "rollup --config rollup.test.config.js",
|
|
14
15
|
"watch": "rollup --config rollup.config.js -w",
|
|
15
|
-
"test": "
|
|
16
|
+
"test": "npm run build && npm run build:test && DEBUG=false karma start test/karma.config.js"
|
|
16
17
|
},
|
|
17
18
|
"devDependencies": {
|
|
18
19
|
"chai": "^4.2.0",
|
package/CHANGELOG.md
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
## [2.1.1](https://github.com/mparticle-integrations/mparticle-javascript-integration-adwords/compare/v2.1.0...v2.1.1) (2021-11-11)
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
### Bug Fixes
|
|
5
|
-
|
|
6
|
-
* Correct send_to in gtag API ([#23](https://github.com/mparticle-integrations/mparticle-javascript-integration-adwords/issues/23)) ([af01adc](https://github.com/mparticle-integrations/mparticle-javascript-integration-adwords/commit/af01adc2b04453f77845e228bff4aa6c49824fde))
|
|
7
|
-
* Prevent unmapped events from being forwarded ([#22](https://github.com/mparticle-integrations/mparticle-javascript-integration-adwords/issues/22)) ([50e6d27](https://github.com/mparticle-integrations/mparticle-javascript-integration-adwords/commit/50e6d279dff666f5621e585878672707a21d911f))
|
|
8
|
-
|
|
9
|
-
## Releases
|
|
10
|
-
--
|
|
11
|
-
|
|
12
|
-
#### 2.1.0 - 2021-10-25
|
|
13
|
-
* Implement Google Site Tag (GTAG) support as an opt-in feature
|
|
14
|
-
|
|
15
|
-
#### 2.0.5 - 2020-11-11
|
|
16
|
-
* There are no code changes in this commit. NPM published 2.0.4 but with the dist/ file from 2.0.3. This commit will include the correct dist/ file as we bump to 2.0.5
|
|
17
|
-
|
|
18
|
-
#### 2.0.4 - 2020-11-10
|
|
19
|
-
* Bugfix - Check window for node environments
|
|
20
|
-
* Bugfix - rename event --> adWordEvent
|
|
21
|
-
|
|
22
|
-
#### 2.0.3 - 2020-02-03
|
|
23
|
-
* Update package.json
|
|
24
|
-
|
|
25
|
-
#### 2.0.2 - 2019-10-03
|
|
26
|
-
* Bugfix - Remove parseInt(conversionId) which could result in NaN and data not sent to AdWords
|
|
27
|
-
* Turn src file into an ESM module
|
|
28
|
-
* Remove isObject dependency
|
|
29
|
-
|
|
30
|
-
#### 2.0.1 - 2019-08-12
|
|
31
|
-
* Bugfix - Refactor calculateJSHash
|