@blotoutio/providers-google-ads-clicks-sdk 0.18.0 → 0.20.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.
Files changed (2) hide show
  1. package/index.js +53 -4
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -1,6 +1,42 @@
1
1
  var ProvidersGoogleAdsClicksSdk = (function () {
2
2
  'use strict';
3
3
 
4
+ const getCookieValue = (key) => {
5
+ try {
6
+ if (!document || !document.cookie) {
7
+ return '';
8
+ }
9
+ const name = `${key}=`;
10
+ const decodedCookie = decodeURIComponent(document.cookie);
11
+ const ca = decodedCookie.split(';');
12
+ for (let i = 0; i < ca.length; i++) {
13
+ let c = ca[i];
14
+ while (c.charAt(0) === ' ') {
15
+ c = c.substring(1);
16
+ }
17
+ if (c.indexOf(name) === 0) {
18
+ return c.substring(name.length, c.length);
19
+ }
20
+ }
21
+ return '';
22
+ }
23
+ catch (_a) {
24
+ return '';
25
+ }
26
+ };
27
+ const setCookie = (key, value) => {
28
+ try {
29
+ if (!document) {
30
+ return;
31
+ }
32
+ document.cookie = `${key}=${value};path=/`;
33
+ }
34
+ catch (_a) {
35
+ return;
36
+ }
37
+ };
38
+
39
+ let googleIntervalCheck = 0;
4
40
  const initGAds = (ID) => {
5
41
  window.dataLayer = window.dataLayer || [];
6
42
  window.gtag = function gtag() {
@@ -29,6 +65,21 @@ var ProvidersGoogleAdsClicksSdk = (function () {
29
65
  if (window.gtag) {
30
66
  window.gtag('config', manifest.variables['tagId']);
31
67
  }
68
+ const isGAdsCookieCreated = getCookieValue('_gAds_loaded');
69
+ if (isGAdsCookieCreated !== '1') {
70
+ const interval = setInterval(() => {
71
+ const isGAdsLoaded = window &&
72
+ !!window.google_tag_manager &&
73
+ !!window.google_tag_manager[manifest.variables['tagId']];
74
+ setCookie('_gAds_loaded', isGAdsLoaded ? '1' : '0');
75
+ googleIntervalCheck++;
76
+ if ((window.google_tag_manager &&
77
+ !!window.google_tag_manager[manifest.variables['tagId']]) ||
78
+ googleIntervalCheck > 15) {
79
+ clearInterval(interval);
80
+ }
81
+ }, 1500);
82
+ }
32
83
  };
33
84
 
34
85
  const getConversionLabel = (eventName, manifestVariables) => {
@@ -78,15 +129,13 @@ var ProvidersGoogleAdsClicksSdk = (function () {
78
129
  };
79
130
 
80
131
  const tag = ({ data, eventName, manifestVariables, eventId }) => {
81
- const isLoaded = window &&
82
- !!window.google_tag_manager &&
83
- !!window.google_tag_manager[manifestVariables['tagId']];
132
+ const isLoaded = (window === null || window === void 0 ? void 0 : window.gtag) && getCookieValue('_gAds_loaded') === '1';
84
133
  if (isLoaded) {
85
134
  handleTag({ data, eventName, manifestVariables, eventId });
86
135
  }
87
136
  return {
88
137
  loaded: isLoaded,
89
- sdkVersion: "0.18.0" ,
138
+ sdkVersion: "0.20.0" ,
90
139
  };
91
140
  };
92
141
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blotoutio/providers-google-ads-clicks-sdk",
3
- "version": "0.18.0",
3
+ "version": "0.20.0",
4
4
  "description": "Google Ads Browser SDK for EdgeTag",
5
5
  "author": "Blotout",
6
6
  "license": "MIT",