@blotoutio/providers-google-ads-clicks-sdk 0.18.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 +11 -0
- package/index.js +112 -0
- package/package.json +21 -0
package/README.md
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# providers-google-ads-clicks-sdk
|
|
2
|
+
|
|
3
|
+
This library was generated with [Nx](https://nx.dev).
|
|
4
|
+
|
|
5
|
+
## Running unit tests
|
|
6
|
+
|
|
7
|
+
Run `nx test providers-google-ads-clicks-sdk` to execute the unit tests via [Jest](https://jestjs.io).
|
|
8
|
+
|
|
9
|
+
## Running lint
|
|
10
|
+
|
|
11
|
+
Run `nx lint providers-google-ads-clicks-sdk` to execute the lint via [ESLint](https://eslint.org/).
|
package/index.js
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
var ProvidersGoogleAdsClicksSdk = (function () {
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
const initGAds = (ID) => {
|
|
5
|
+
window.dataLayer = window.dataLayer || [];
|
|
6
|
+
window.gtag = function gtag() {
|
|
7
|
+
// eslint-disable-next-line prefer-rest-params
|
|
8
|
+
window.dataLayer.push(arguments);
|
|
9
|
+
};
|
|
10
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
11
|
+
// @ts-ignore
|
|
12
|
+
window.gtag('js', new Date());
|
|
13
|
+
const element = document.createElement('script');
|
|
14
|
+
element.async = !0;
|
|
15
|
+
element.src = `https://www.googletagmanager.com/gtag/js?id=${ID}`;
|
|
16
|
+
const script = document.getElementsByTagName('script')[0];
|
|
17
|
+
if (script && script.parentNode) {
|
|
18
|
+
script.parentNode.insertBefore(element, script);
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
const init = ({ manifest }) => {
|
|
22
|
+
if (!window || !manifest.variables || !(manifest === null || manifest === void 0 ? void 0 : manifest.variables['tagId'])) {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
if (!window.google_tag_manager ||
|
|
26
|
+
!window.google_tag_manager[manifest.variables['tagId']]) {
|
|
27
|
+
initGAds(manifest.variables['tagId']);
|
|
28
|
+
}
|
|
29
|
+
if (window.gtag) {
|
|
30
|
+
window.gtag('config', manifest.variables['tagId']);
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
const getConversionLabel = (eventName, manifestVariables) => {
|
|
35
|
+
if (!manifestVariables) {
|
|
36
|
+
return '';
|
|
37
|
+
}
|
|
38
|
+
let mappings = [];
|
|
39
|
+
try {
|
|
40
|
+
mappings = manifestVariables['conversionMappings'];
|
|
41
|
+
}
|
|
42
|
+
catch (e) {
|
|
43
|
+
mappings = [];
|
|
44
|
+
console.log(e);
|
|
45
|
+
}
|
|
46
|
+
const mapping = mappings.find((mapping) => mapping.eventName === eventName);
|
|
47
|
+
return mapping === null || mapping === void 0 ? void 0 : mapping.browserConversionLabel;
|
|
48
|
+
};
|
|
49
|
+
const getEventData = (data) => {
|
|
50
|
+
const eventData = {};
|
|
51
|
+
if (!data) {
|
|
52
|
+
return eventData;
|
|
53
|
+
}
|
|
54
|
+
if (data['value']) {
|
|
55
|
+
eventData.value = data['value'];
|
|
56
|
+
}
|
|
57
|
+
if (data['currency']) {
|
|
58
|
+
eventData.currency = data['currency'];
|
|
59
|
+
}
|
|
60
|
+
if (data['orderId']) {
|
|
61
|
+
eventData.transaction_id = data['orderId'];
|
|
62
|
+
}
|
|
63
|
+
return eventData;
|
|
64
|
+
};
|
|
65
|
+
const handleTag = ({ data, eventName, manifestVariables, }) => {
|
|
66
|
+
if (!eventName ||
|
|
67
|
+
!window.gtag ||
|
|
68
|
+
!manifestVariables ||
|
|
69
|
+
!manifestVariables['tagId']) {
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
const conversionLabel = getConversionLabel(eventName, manifestVariables);
|
|
73
|
+
const eventData = getEventData(data);
|
|
74
|
+
if (!conversionLabel) {
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
window.gtag('event', 'conversion', Object.assign(Object.assign({ send_to: conversionLabel }, eventData), { app: 'blotout' }));
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
const tag = ({ data, eventName, manifestVariables, eventId }) => {
|
|
81
|
+
const isLoaded = window &&
|
|
82
|
+
!!window.google_tag_manager &&
|
|
83
|
+
!!window.google_tag_manager[manifestVariables['tagId']];
|
|
84
|
+
if (isLoaded) {
|
|
85
|
+
handleTag({ data, eventName, manifestVariables, eventId });
|
|
86
|
+
}
|
|
87
|
+
return {
|
|
88
|
+
loaded: isLoaded,
|
|
89
|
+
sdkVersion: "0.18.0" ,
|
|
90
|
+
};
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
const data = {
|
|
94
|
+
name: 'googleAdsClicks',
|
|
95
|
+
init,
|
|
96
|
+
tag,
|
|
97
|
+
};
|
|
98
|
+
try {
|
|
99
|
+
if (window) {
|
|
100
|
+
if (!window.edgetagProviders) {
|
|
101
|
+
window.edgetagProviders = [];
|
|
102
|
+
}
|
|
103
|
+
window.edgetagProviders.push(data);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
catch (_a) {
|
|
107
|
+
// No window
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
return data;
|
|
111
|
+
|
|
112
|
+
})();
|
package/package.json
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@blotoutio/providers-google-ads-clicks-sdk",
|
|
3
|
+
"version": "0.18.0",
|
|
4
|
+
"description": "Google Ads Browser SDK for EdgeTag",
|
|
5
|
+
"author": "Blotout",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"homepage": "https://github.com/blotoutio/edgetag-sdk",
|
|
8
|
+
"publishConfig": {
|
|
9
|
+
"access": "public"
|
|
10
|
+
},
|
|
11
|
+
"main": "./index.js",
|
|
12
|
+
"repository": {
|
|
13
|
+
"type": "git",
|
|
14
|
+
"url": "git+https://github.com/blotoutio/edgetag-sdk.git"
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"index.js",
|
|
18
|
+
"package.json",
|
|
19
|
+
"README.md"
|
|
20
|
+
]
|
|
21
|
+
}
|