@blotoutio/providers-google-ads-clicks-sdk 0.26.5 → 0.26.6

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 ADDED
@@ -0,0 +1,163 @@
1
+ 'use strict';
2
+
3
+ const getCookieValue = (key) => {
4
+ try {
5
+ if (!document || !document.cookie) {
6
+ return '';
7
+ }
8
+ const name = `${key}=`;
9
+ const decodedCookie = decodeURIComponent(document.cookie);
10
+ const ca = decodedCookie.split(';');
11
+ for (let i = 0; i < ca.length; i++) {
12
+ let c = ca[i];
13
+ while (c.charAt(0) === ' ') {
14
+ c = c.substring(1);
15
+ }
16
+ if (c.indexOf(name) === 0) {
17
+ return c.substring(name.length, c.length);
18
+ }
19
+ }
20
+ return '';
21
+ }
22
+ catch {
23
+ return '';
24
+ }
25
+ };
26
+ const setCookie = (key, value) => {
27
+ try {
28
+ if (!document) {
29
+ return;
30
+ }
31
+ document.cookie = `${key}=${value};path=/`;
32
+ }
33
+ catch {
34
+ return;
35
+ }
36
+ };
37
+
38
+ let googleIntervalCheck = 0;
39
+ const initGAds = (ID) => {
40
+ window.dataLayer = window.dataLayer || [];
41
+ window.gtag = function gtag() {
42
+ // eslint-disable-next-line prefer-rest-params
43
+ window.dataLayer.push(arguments);
44
+ };
45
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
46
+ // @ts-ignore
47
+ window.gtag('js', new Date());
48
+ const element = document.createElement('script');
49
+ element.async = !0;
50
+ element.src = `https://www.googletagmanager.com/gtag/js?id=${ID}`;
51
+ const script = document.getElementsByTagName('script')[0];
52
+ if (script && script.parentNode) {
53
+ script.parentNode.insertBefore(element, script);
54
+ }
55
+ };
56
+ const init = ({ manifest }) => {
57
+ if (!window || !manifest.variables || !(manifest === null || manifest === void 0 ? void 0 : manifest.variables['tagId'])) {
58
+ return;
59
+ }
60
+ if (!window.google_tag_manager ||
61
+ !window.google_tag_manager[manifest.variables['tagId']]) {
62
+ initGAds(manifest.variables['tagId']);
63
+ }
64
+ if (window.gtag) {
65
+ window.gtag('config', manifest.variables['tagId']);
66
+ }
67
+ const isGAdsCookieCreated = getCookieValue('_gAds_loaded');
68
+ if (isGAdsCookieCreated !== '1') {
69
+ const interval = setInterval(() => {
70
+ const isGAdsLoaded = window &&
71
+ !!window.google_tag_manager &&
72
+ !!window.google_tag_manager[manifest.variables['tagId']];
73
+ setCookie('_gAds_loaded', isGAdsLoaded ? '1' : '0');
74
+ googleIntervalCheck++;
75
+ if ((window.google_tag_manager &&
76
+ !!window.google_tag_manager[manifest.variables['tagId']]) ||
77
+ googleIntervalCheck > 15) {
78
+ clearInterval(interval);
79
+ }
80
+ }, 1500);
81
+ }
82
+ };
83
+
84
+ const getConversionLabel = (eventName, manifestVariables) => {
85
+ if (!manifestVariables) {
86
+ return '';
87
+ }
88
+ let mappings = [];
89
+ try {
90
+ mappings = manifestVariables['conversionMappings'];
91
+ }
92
+ catch (e) {
93
+ mappings = [];
94
+ console.log(e);
95
+ }
96
+ const mapping = mappings.find((mapping) => mapping.eventName === eventName);
97
+ return mapping === null || mapping === void 0 ? void 0 : mapping.browserConversionLabel;
98
+ };
99
+ const getEventData = (data) => {
100
+ const eventData = {};
101
+ if (!data) {
102
+ return eventData;
103
+ }
104
+ if (data['value']) {
105
+ eventData.value = data['value'];
106
+ }
107
+ if (data['currency']) {
108
+ eventData.currency = data['currency'];
109
+ }
110
+ if (data['orderId']) {
111
+ eventData.transaction_id = data['orderId'];
112
+ }
113
+ return eventData;
114
+ };
115
+ const handleTag = ({ data, eventName, manifestVariables, }) => {
116
+ if (!eventName ||
117
+ !window.gtag ||
118
+ !manifestVariables ||
119
+ !manifestVariables['tagId']) {
120
+ return;
121
+ }
122
+ const conversionLabel = getConversionLabel(eventName, manifestVariables);
123
+ const eventData = getEventData(data);
124
+ if (!conversionLabel) {
125
+ return;
126
+ }
127
+ window.gtag('event', 'conversion', {
128
+ send_to: conversionLabel,
129
+ ...eventData,
130
+ app: 'blotout',
131
+ });
132
+ };
133
+
134
+ const tag = ({ data, eventName, manifestVariables, eventId }) => {
135
+ const isInIframe = window.self !== window.top;
136
+ const isLoaded = (window === null || window === void 0 ? void 0 : window.gtag) && getCookieValue('_gAds_loaded') === '1' && !isInIframe;
137
+ if (isLoaded) {
138
+ handleTag({ data, eventName, manifestVariables, eventId });
139
+ }
140
+ return {
141
+ loaded: isLoaded,
142
+ sdkVersion: "0.26.6" ,
143
+ };
144
+ };
145
+
146
+ const data = {
147
+ name: 'googleAdsClicks',
148
+ init,
149
+ tag,
150
+ };
151
+ try {
152
+ if (window) {
153
+ if (!window.edgetagProviders) {
154
+ window.edgetagProviders = [];
155
+ }
156
+ window.edgetagProviders.push(data);
157
+ }
158
+ }
159
+ catch {
160
+ // No window
161
+ }
162
+
163
+ module.exports = data;
package/index.js CHANGED
@@ -140,7 +140,7 @@ var ProvidersGoogleAdsClicksSdk = (function () {
140
140
  }
141
141
  return {
142
142
  loaded: isLoaded,
143
- sdkVersion: "0.26.5" ,
143
+ sdkVersion: "0.26.6" ,
144
144
  };
145
145
  };
146
146
 
package/index.mjs ADDED
@@ -0,0 +1,161 @@
1
+ const getCookieValue = (key) => {
2
+ try {
3
+ if (!document || !document.cookie) {
4
+ return '';
5
+ }
6
+ const name = `${key}=`;
7
+ const decodedCookie = decodeURIComponent(document.cookie);
8
+ const ca = decodedCookie.split(';');
9
+ for (let i = 0; i < ca.length; i++) {
10
+ let c = ca[i];
11
+ while (c.charAt(0) === ' ') {
12
+ c = c.substring(1);
13
+ }
14
+ if (c.indexOf(name) === 0) {
15
+ return c.substring(name.length, c.length);
16
+ }
17
+ }
18
+ return '';
19
+ }
20
+ catch {
21
+ return '';
22
+ }
23
+ };
24
+ const setCookie = (key, value) => {
25
+ try {
26
+ if (!document) {
27
+ return;
28
+ }
29
+ document.cookie = `${key}=${value};path=/`;
30
+ }
31
+ catch {
32
+ return;
33
+ }
34
+ };
35
+
36
+ let googleIntervalCheck = 0;
37
+ const initGAds = (ID) => {
38
+ window.dataLayer = window.dataLayer || [];
39
+ window.gtag = function gtag() {
40
+ // eslint-disable-next-line prefer-rest-params
41
+ window.dataLayer.push(arguments);
42
+ };
43
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
44
+ // @ts-ignore
45
+ window.gtag('js', new Date());
46
+ const element = document.createElement('script');
47
+ element.async = !0;
48
+ element.src = `https://www.googletagmanager.com/gtag/js?id=${ID}`;
49
+ const script = document.getElementsByTagName('script')[0];
50
+ if (script && script.parentNode) {
51
+ script.parentNode.insertBefore(element, script);
52
+ }
53
+ };
54
+ const init = ({ manifest }) => {
55
+ if (!window || !manifest.variables || !(manifest === null || manifest === void 0 ? void 0 : manifest.variables['tagId'])) {
56
+ return;
57
+ }
58
+ if (!window.google_tag_manager ||
59
+ !window.google_tag_manager[manifest.variables['tagId']]) {
60
+ initGAds(manifest.variables['tagId']);
61
+ }
62
+ if (window.gtag) {
63
+ window.gtag('config', manifest.variables['tagId']);
64
+ }
65
+ const isGAdsCookieCreated = getCookieValue('_gAds_loaded');
66
+ if (isGAdsCookieCreated !== '1') {
67
+ const interval = setInterval(() => {
68
+ const isGAdsLoaded = window &&
69
+ !!window.google_tag_manager &&
70
+ !!window.google_tag_manager[manifest.variables['tagId']];
71
+ setCookie('_gAds_loaded', isGAdsLoaded ? '1' : '0');
72
+ googleIntervalCheck++;
73
+ if ((window.google_tag_manager &&
74
+ !!window.google_tag_manager[manifest.variables['tagId']]) ||
75
+ googleIntervalCheck > 15) {
76
+ clearInterval(interval);
77
+ }
78
+ }, 1500);
79
+ }
80
+ };
81
+
82
+ const getConversionLabel = (eventName, manifestVariables) => {
83
+ if (!manifestVariables) {
84
+ return '';
85
+ }
86
+ let mappings = [];
87
+ try {
88
+ mappings = manifestVariables['conversionMappings'];
89
+ }
90
+ catch (e) {
91
+ mappings = [];
92
+ console.log(e);
93
+ }
94
+ const mapping = mappings.find((mapping) => mapping.eventName === eventName);
95
+ return mapping === null || mapping === void 0 ? void 0 : mapping.browserConversionLabel;
96
+ };
97
+ const getEventData = (data) => {
98
+ const eventData = {};
99
+ if (!data) {
100
+ return eventData;
101
+ }
102
+ if (data['value']) {
103
+ eventData.value = data['value'];
104
+ }
105
+ if (data['currency']) {
106
+ eventData.currency = data['currency'];
107
+ }
108
+ if (data['orderId']) {
109
+ eventData.transaction_id = data['orderId'];
110
+ }
111
+ return eventData;
112
+ };
113
+ const handleTag = ({ data, eventName, manifestVariables, }) => {
114
+ if (!eventName ||
115
+ !window.gtag ||
116
+ !manifestVariables ||
117
+ !manifestVariables['tagId']) {
118
+ return;
119
+ }
120
+ const conversionLabel = getConversionLabel(eventName, manifestVariables);
121
+ const eventData = getEventData(data);
122
+ if (!conversionLabel) {
123
+ return;
124
+ }
125
+ window.gtag('event', 'conversion', {
126
+ send_to: conversionLabel,
127
+ ...eventData,
128
+ app: 'blotout',
129
+ });
130
+ };
131
+
132
+ const tag = ({ data, eventName, manifestVariables, eventId }) => {
133
+ const isInIframe = window.self !== window.top;
134
+ const isLoaded = (window === null || window === void 0 ? void 0 : window.gtag) && getCookieValue('_gAds_loaded') === '1' && !isInIframe;
135
+ if (isLoaded) {
136
+ handleTag({ data, eventName, manifestVariables, eventId });
137
+ }
138
+ return {
139
+ loaded: isLoaded,
140
+ sdkVersion: "0.26.6" ,
141
+ };
142
+ };
143
+
144
+ const data = {
145
+ name: 'googleAdsClicks',
146
+ init,
147
+ tag,
148
+ };
149
+ try {
150
+ if (window) {
151
+ if (!window.edgetagProviders) {
152
+ window.edgetagProviders = [];
153
+ }
154
+ window.edgetagProviders.push(data);
155
+ }
156
+ }
157
+ catch {
158
+ // No window
159
+ }
160
+
161
+ export { data as default };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blotoutio/providers-google-ads-clicks-sdk",
3
- "version": "0.26.5",
3
+ "version": "0.26.6",
4
4
  "description": "Google Ads Browser SDK for EdgeTag",
5
5
  "author": "Blotout",
6
6
  "license": "MIT",
@@ -8,13 +8,16 @@
8
8
  "publishConfig": {
9
9
  "access": "public"
10
10
  },
11
- "main": "./index.js",
11
+ "main": "./index.cjs.js",
12
+ "module": "./index.mjs",
12
13
  "repository": {
13
14
  "type": "git",
14
15
  "url": "git+https://github.com/blotoutio/edgetag-sdk.git"
15
16
  },
16
17
  "files": [
17
18
  "index.js",
19
+ "index.cjs.js",
20
+ "index.mjs",
18
21
  "package.json",
19
22
  "README.md"
20
23
  ]