@blotoutio/providers-google-ads-clicks-sdk 0.61.0 → 0.62.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.
- package/index.cjs.js +62 -11
- package/index.js +62 -11
- package/index.mjs +62 -11
- package/package.json +1 -1
package/index.cjs.js
CHANGED
|
@@ -88,18 +88,22 @@ const initGAds = (ID, executionContext) => {
|
|
|
88
88
|
}
|
|
89
89
|
};
|
|
90
90
|
const init = ({ manifest, executionContext }) => {
|
|
91
|
-
var _a;
|
|
91
|
+
var _a, _b;
|
|
92
92
|
if (!window || !((_a = manifest === null || manifest === void 0 ? void 0 : manifest.variables) === null || _a === void 0 ? void 0 : _a['tagId'])) {
|
|
93
93
|
return;
|
|
94
94
|
}
|
|
95
|
+
const customConfig = {
|
|
96
|
+
send_page_view: false,
|
|
97
|
+
};
|
|
98
|
+
if (((_b = manifest.variables) === null || _b === void 0 ? void 0 : _b['enhancedConversionsSetting']) === 'gtag') {
|
|
99
|
+
customConfig['allow_enhanced_conversions'] = true;
|
|
100
|
+
}
|
|
95
101
|
if (!window.google_tag_manager ||
|
|
96
102
|
!window.google_tag_manager[manifest.variables['tagId']]) {
|
|
97
103
|
initGAds(manifest.variables['tagId'], executionContext);
|
|
98
104
|
}
|
|
99
105
|
if (window.gtag) {
|
|
100
|
-
window.gtag('config', manifest.variables['tagId'],
|
|
101
|
-
send_page_view: false,
|
|
102
|
-
});
|
|
106
|
+
window.gtag('config', manifest.variables['tagId'], customConfig);
|
|
103
107
|
}
|
|
104
108
|
};
|
|
105
109
|
|
|
@@ -161,7 +165,43 @@ const getCartData = (variables, data) => {
|
|
|
161
165
|
}
|
|
162
166
|
return cartData;
|
|
163
167
|
};
|
|
164
|
-
const
|
|
168
|
+
const getUserData = (destination) => {
|
|
169
|
+
var _a, _b, _c;
|
|
170
|
+
let kv = {};
|
|
171
|
+
const userData = {};
|
|
172
|
+
const address = {};
|
|
173
|
+
try {
|
|
174
|
+
kv =
|
|
175
|
+
(_c = (_b = (_a = JSON.parse(window.sessionStorage.getItem('_workerStoreMultiple') || '{}')) === null || _a === void 0 ? void 0 : _a[destination]) === null || _b === void 0 ? void 0 : _b['kv']) !== null && _c !== void 0 ? _c : {};
|
|
176
|
+
}
|
|
177
|
+
catch (e) {
|
|
178
|
+
console.error('Unable to get user data from session storage');
|
|
179
|
+
kv = {};
|
|
180
|
+
}
|
|
181
|
+
if (kv['email']) {
|
|
182
|
+
userData['email'] = kv['email'];
|
|
183
|
+
}
|
|
184
|
+
if (kv['phone']) {
|
|
185
|
+
userData['phone_number'] = kv['phone'];
|
|
186
|
+
}
|
|
187
|
+
if (kv['firstName']) {
|
|
188
|
+
address['first_name'] = kv['firstName'];
|
|
189
|
+
}
|
|
190
|
+
if (kv['lastName']) {
|
|
191
|
+
address['last_name'] = kv['lastName'];
|
|
192
|
+
}
|
|
193
|
+
if (kv['zip']) {
|
|
194
|
+
address['postal_code'] = kv['zip'];
|
|
195
|
+
}
|
|
196
|
+
if (kv['city']) {
|
|
197
|
+
address['city'] = kv['city'];
|
|
198
|
+
}
|
|
199
|
+
if (Object.keys(address).length) {
|
|
200
|
+
userData['address'] = [address];
|
|
201
|
+
}
|
|
202
|
+
return userData;
|
|
203
|
+
};
|
|
204
|
+
const handleTag = ({ data, eventName, manifestVariables, destination, }) => {
|
|
165
205
|
if (!eventName ||
|
|
166
206
|
!window.gtag ||
|
|
167
207
|
!manifestVariables ||
|
|
@@ -169,11 +209,15 @@ const handleTag = ({ data, eventName, manifestVariables, }) => {
|
|
|
169
209
|
return;
|
|
170
210
|
}
|
|
171
211
|
const conversionLabel = getConversionLabel(eventName, manifestVariables);
|
|
172
|
-
const eventData = getEventData(data);
|
|
173
|
-
const cartData = getCartData(manifestVariables, data);
|
|
174
212
|
if (!conversionLabel) {
|
|
175
213
|
return;
|
|
176
214
|
}
|
|
215
|
+
if (manifestVariables['enhancedConversionsSetting'] === 'gtag' &&
|
|
216
|
+
destination) {
|
|
217
|
+
window.gtag('set', 'user_data', getUserData(destination));
|
|
218
|
+
}
|
|
219
|
+
const eventData = getEventData(data);
|
|
220
|
+
const cartData = getCartData(manifestVariables, data);
|
|
177
221
|
window.gtag('event', 'conversion', {
|
|
178
222
|
send_to: conversionLabel,
|
|
179
223
|
...eventData,
|
|
@@ -199,7 +243,8 @@ const parseCookies = (cookie) => {
|
|
|
199
243
|
return Object.fromEntries(cookie
|
|
200
244
|
.split(/;\s+/)
|
|
201
245
|
.map((r) => r.split('=').map((str) => str.trim()))
|
|
202
|
-
.map(([cookieKey,
|
|
246
|
+
.map(([cookieKey, ...cookieValues]) => {
|
|
247
|
+
const cookieValue = cookieValues.join('=');
|
|
203
248
|
if (!cookieKey) {
|
|
204
249
|
return [];
|
|
205
250
|
}
|
|
@@ -217,14 +262,20 @@ const parseCookies = (cookie) => {
|
|
|
217
262
|
}));
|
|
218
263
|
};
|
|
219
264
|
|
|
220
|
-
const tag = ({ data, eventName, manifestVariables, eventId }) => {
|
|
265
|
+
const tag = ({ data, eventName, manifestVariables, eventId, destination, }) => {
|
|
221
266
|
const isLoaded = window && window.gtag && !!getCookieValue('_gcl_au');
|
|
222
267
|
if (isLoaded) {
|
|
223
|
-
handleTag({
|
|
268
|
+
handleTag({
|
|
269
|
+
data,
|
|
270
|
+
eventName,
|
|
271
|
+
manifestVariables,
|
|
272
|
+
eventId,
|
|
273
|
+
destination,
|
|
274
|
+
});
|
|
224
275
|
}
|
|
225
276
|
return {
|
|
226
277
|
loaded: isLoaded,
|
|
227
|
-
sdkVersion: "0.
|
|
278
|
+
sdkVersion: "0.62.1" ,
|
|
228
279
|
};
|
|
229
280
|
};
|
|
230
281
|
|
package/index.js
CHANGED
|
@@ -89,18 +89,22 @@ var ProvidersGoogleAdsClicksSdk = (function () {
|
|
|
89
89
|
}
|
|
90
90
|
};
|
|
91
91
|
const init = ({ manifest, executionContext }) => {
|
|
92
|
-
var _a;
|
|
92
|
+
var _a, _b;
|
|
93
93
|
if (!window || !((_a = manifest === null || manifest === void 0 ? void 0 : manifest.variables) === null || _a === void 0 ? void 0 : _a['tagId'])) {
|
|
94
94
|
return;
|
|
95
95
|
}
|
|
96
|
+
const customConfig = {
|
|
97
|
+
send_page_view: false,
|
|
98
|
+
};
|
|
99
|
+
if (((_b = manifest.variables) === null || _b === void 0 ? void 0 : _b['enhancedConversionsSetting']) === 'gtag') {
|
|
100
|
+
customConfig['allow_enhanced_conversions'] = true;
|
|
101
|
+
}
|
|
96
102
|
if (!window.google_tag_manager ||
|
|
97
103
|
!window.google_tag_manager[manifest.variables['tagId']]) {
|
|
98
104
|
initGAds(manifest.variables['tagId'], executionContext);
|
|
99
105
|
}
|
|
100
106
|
if (window.gtag) {
|
|
101
|
-
window.gtag('config', manifest.variables['tagId'],
|
|
102
|
-
send_page_view: false,
|
|
103
|
-
});
|
|
107
|
+
window.gtag('config', manifest.variables['tagId'], customConfig);
|
|
104
108
|
}
|
|
105
109
|
};
|
|
106
110
|
|
|
@@ -162,7 +166,43 @@ var ProvidersGoogleAdsClicksSdk = (function () {
|
|
|
162
166
|
}
|
|
163
167
|
return cartData;
|
|
164
168
|
};
|
|
165
|
-
const
|
|
169
|
+
const getUserData = (destination) => {
|
|
170
|
+
var _a, _b, _c;
|
|
171
|
+
let kv = {};
|
|
172
|
+
const userData = {};
|
|
173
|
+
const address = {};
|
|
174
|
+
try {
|
|
175
|
+
kv =
|
|
176
|
+
(_c = (_b = (_a = JSON.parse(window.sessionStorage.getItem('_workerStoreMultiple') || '{}')) === null || _a === void 0 ? void 0 : _a[destination]) === null || _b === void 0 ? void 0 : _b['kv']) !== null && _c !== void 0 ? _c : {};
|
|
177
|
+
}
|
|
178
|
+
catch (e) {
|
|
179
|
+
console.error('Unable to get user data from session storage');
|
|
180
|
+
kv = {};
|
|
181
|
+
}
|
|
182
|
+
if (kv['email']) {
|
|
183
|
+
userData['email'] = kv['email'];
|
|
184
|
+
}
|
|
185
|
+
if (kv['phone']) {
|
|
186
|
+
userData['phone_number'] = kv['phone'];
|
|
187
|
+
}
|
|
188
|
+
if (kv['firstName']) {
|
|
189
|
+
address['first_name'] = kv['firstName'];
|
|
190
|
+
}
|
|
191
|
+
if (kv['lastName']) {
|
|
192
|
+
address['last_name'] = kv['lastName'];
|
|
193
|
+
}
|
|
194
|
+
if (kv['zip']) {
|
|
195
|
+
address['postal_code'] = kv['zip'];
|
|
196
|
+
}
|
|
197
|
+
if (kv['city']) {
|
|
198
|
+
address['city'] = kv['city'];
|
|
199
|
+
}
|
|
200
|
+
if (Object.keys(address).length) {
|
|
201
|
+
userData['address'] = [address];
|
|
202
|
+
}
|
|
203
|
+
return userData;
|
|
204
|
+
};
|
|
205
|
+
const handleTag = ({ data, eventName, manifestVariables, destination, }) => {
|
|
166
206
|
if (!eventName ||
|
|
167
207
|
!window.gtag ||
|
|
168
208
|
!manifestVariables ||
|
|
@@ -170,11 +210,15 @@ var ProvidersGoogleAdsClicksSdk = (function () {
|
|
|
170
210
|
return;
|
|
171
211
|
}
|
|
172
212
|
const conversionLabel = getConversionLabel(eventName, manifestVariables);
|
|
173
|
-
const eventData = getEventData(data);
|
|
174
|
-
const cartData = getCartData(manifestVariables, data);
|
|
175
213
|
if (!conversionLabel) {
|
|
176
214
|
return;
|
|
177
215
|
}
|
|
216
|
+
if (manifestVariables['enhancedConversionsSetting'] === 'gtag' &&
|
|
217
|
+
destination) {
|
|
218
|
+
window.gtag('set', 'user_data', getUserData(destination));
|
|
219
|
+
}
|
|
220
|
+
const eventData = getEventData(data);
|
|
221
|
+
const cartData = getCartData(manifestVariables, data);
|
|
178
222
|
window.gtag('event', 'conversion', {
|
|
179
223
|
send_to: conversionLabel,
|
|
180
224
|
...eventData,
|
|
@@ -200,7 +244,8 @@ var ProvidersGoogleAdsClicksSdk = (function () {
|
|
|
200
244
|
return Object.fromEntries(cookie
|
|
201
245
|
.split(/;\s+/)
|
|
202
246
|
.map((r) => r.split('=').map((str) => str.trim()))
|
|
203
|
-
.map(([cookieKey,
|
|
247
|
+
.map(([cookieKey, ...cookieValues]) => {
|
|
248
|
+
const cookieValue = cookieValues.join('=');
|
|
204
249
|
if (!cookieKey) {
|
|
205
250
|
return [];
|
|
206
251
|
}
|
|
@@ -218,14 +263,20 @@ var ProvidersGoogleAdsClicksSdk = (function () {
|
|
|
218
263
|
}));
|
|
219
264
|
};
|
|
220
265
|
|
|
221
|
-
const tag = ({ data, eventName, manifestVariables, eventId }) => {
|
|
266
|
+
const tag = ({ data, eventName, manifestVariables, eventId, destination, }) => {
|
|
222
267
|
const isLoaded = window && window.gtag && !!getCookieValue('_gcl_au');
|
|
223
268
|
if (isLoaded) {
|
|
224
|
-
handleTag({
|
|
269
|
+
handleTag({
|
|
270
|
+
data,
|
|
271
|
+
eventName,
|
|
272
|
+
manifestVariables,
|
|
273
|
+
eventId,
|
|
274
|
+
destination,
|
|
275
|
+
});
|
|
225
276
|
}
|
|
226
277
|
return {
|
|
227
278
|
loaded: isLoaded,
|
|
228
|
-
sdkVersion: "0.
|
|
279
|
+
sdkVersion: "0.62.1" ,
|
|
229
280
|
};
|
|
230
281
|
};
|
|
231
282
|
|
package/index.mjs
CHANGED
|
@@ -86,18 +86,22 @@ const initGAds = (ID, executionContext) => {
|
|
|
86
86
|
}
|
|
87
87
|
};
|
|
88
88
|
const init = ({ manifest, executionContext }) => {
|
|
89
|
-
var _a;
|
|
89
|
+
var _a, _b;
|
|
90
90
|
if (!window || !((_a = manifest === null || manifest === void 0 ? void 0 : manifest.variables) === null || _a === void 0 ? void 0 : _a['tagId'])) {
|
|
91
91
|
return;
|
|
92
92
|
}
|
|
93
|
+
const customConfig = {
|
|
94
|
+
send_page_view: false,
|
|
95
|
+
};
|
|
96
|
+
if (((_b = manifest.variables) === null || _b === void 0 ? void 0 : _b['enhancedConversionsSetting']) === 'gtag') {
|
|
97
|
+
customConfig['allow_enhanced_conversions'] = true;
|
|
98
|
+
}
|
|
93
99
|
if (!window.google_tag_manager ||
|
|
94
100
|
!window.google_tag_manager[manifest.variables['tagId']]) {
|
|
95
101
|
initGAds(manifest.variables['tagId'], executionContext);
|
|
96
102
|
}
|
|
97
103
|
if (window.gtag) {
|
|
98
|
-
window.gtag('config', manifest.variables['tagId'],
|
|
99
|
-
send_page_view: false,
|
|
100
|
-
});
|
|
104
|
+
window.gtag('config', manifest.variables['tagId'], customConfig);
|
|
101
105
|
}
|
|
102
106
|
};
|
|
103
107
|
|
|
@@ -159,7 +163,43 @@ const getCartData = (variables, data) => {
|
|
|
159
163
|
}
|
|
160
164
|
return cartData;
|
|
161
165
|
};
|
|
162
|
-
const
|
|
166
|
+
const getUserData = (destination) => {
|
|
167
|
+
var _a, _b, _c;
|
|
168
|
+
let kv = {};
|
|
169
|
+
const userData = {};
|
|
170
|
+
const address = {};
|
|
171
|
+
try {
|
|
172
|
+
kv =
|
|
173
|
+
(_c = (_b = (_a = JSON.parse(window.sessionStorage.getItem('_workerStoreMultiple') || '{}')) === null || _a === void 0 ? void 0 : _a[destination]) === null || _b === void 0 ? void 0 : _b['kv']) !== null && _c !== void 0 ? _c : {};
|
|
174
|
+
}
|
|
175
|
+
catch (e) {
|
|
176
|
+
console.error('Unable to get user data from session storage');
|
|
177
|
+
kv = {};
|
|
178
|
+
}
|
|
179
|
+
if (kv['email']) {
|
|
180
|
+
userData['email'] = kv['email'];
|
|
181
|
+
}
|
|
182
|
+
if (kv['phone']) {
|
|
183
|
+
userData['phone_number'] = kv['phone'];
|
|
184
|
+
}
|
|
185
|
+
if (kv['firstName']) {
|
|
186
|
+
address['first_name'] = kv['firstName'];
|
|
187
|
+
}
|
|
188
|
+
if (kv['lastName']) {
|
|
189
|
+
address['last_name'] = kv['lastName'];
|
|
190
|
+
}
|
|
191
|
+
if (kv['zip']) {
|
|
192
|
+
address['postal_code'] = kv['zip'];
|
|
193
|
+
}
|
|
194
|
+
if (kv['city']) {
|
|
195
|
+
address['city'] = kv['city'];
|
|
196
|
+
}
|
|
197
|
+
if (Object.keys(address).length) {
|
|
198
|
+
userData['address'] = [address];
|
|
199
|
+
}
|
|
200
|
+
return userData;
|
|
201
|
+
};
|
|
202
|
+
const handleTag = ({ data, eventName, manifestVariables, destination, }) => {
|
|
163
203
|
if (!eventName ||
|
|
164
204
|
!window.gtag ||
|
|
165
205
|
!manifestVariables ||
|
|
@@ -167,11 +207,15 @@ const handleTag = ({ data, eventName, manifestVariables, }) => {
|
|
|
167
207
|
return;
|
|
168
208
|
}
|
|
169
209
|
const conversionLabel = getConversionLabel(eventName, manifestVariables);
|
|
170
|
-
const eventData = getEventData(data);
|
|
171
|
-
const cartData = getCartData(manifestVariables, data);
|
|
172
210
|
if (!conversionLabel) {
|
|
173
211
|
return;
|
|
174
212
|
}
|
|
213
|
+
if (manifestVariables['enhancedConversionsSetting'] === 'gtag' &&
|
|
214
|
+
destination) {
|
|
215
|
+
window.gtag('set', 'user_data', getUserData(destination));
|
|
216
|
+
}
|
|
217
|
+
const eventData = getEventData(data);
|
|
218
|
+
const cartData = getCartData(manifestVariables, data);
|
|
175
219
|
window.gtag('event', 'conversion', {
|
|
176
220
|
send_to: conversionLabel,
|
|
177
221
|
...eventData,
|
|
@@ -197,7 +241,8 @@ const parseCookies = (cookie) => {
|
|
|
197
241
|
return Object.fromEntries(cookie
|
|
198
242
|
.split(/;\s+/)
|
|
199
243
|
.map((r) => r.split('=').map((str) => str.trim()))
|
|
200
|
-
.map(([cookieKey,
|
|
244
|
+
.map(([cookieKey, ...cookieValues]) => {
|
|
245
|
+
const cookieValue = cookieValues.join('=');
|
|
201
246
|
if (!cookieKey) {
|
|
202
247
|
return [];
|
|
203
248
|
}
|
|
@@ -215,14 +260,20 @@ const parseCookies = (cookie) => {
|
|
|
215
260
|
}));
|
|
216
261
|
};
|
|
217
262
|
|
|
218
|
-
const tag = ({ data, eventName, manifestVariables, eventId }) => {
|
|
263
|
+
const tag = ({ data, eventName, manifestVariables, eventId, destination, }) => {
|
|
219
264
|
const isLoaded = window && window.gtag && !!getCookieValue('_gcl_au');
|
|
220
265
|
if (isLoaded) {
|
|
221
|
-
handleTag({
|
|
266
|
+
handleTag({
|
|
267
|
+
data,
|
|
268
|
+
eventName,
|
|
269
|
+
manifestVariables,
|
|
270
|
+
eventId,
|
|
271
|
+
destination,
|
|
272
|
+
});
|
|
222
273
|
}
|
|
223
274
|
return {
|
|
224
275
|
loaded: isLoaded,
|
|
225
|
-
sdkVersion: "0.
|
|
276
|
+
sdkVersion: "0.62.1" ,
|
|
226
277
|
};
|
|
227
278
|
};
|
|
228
279
|
|