@blotoutio/providers-google-ads-clicks-sdk 1.63.1 → 1.63.3

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 (4) hide show
  1. package/index.cjs.js +78 -10
  2. package/index.js +78 -10
  3. package/index.mjs +78 -10
  4. package/package.json +1 -1
package/index.cjs.js CHANGED
@@ -805,7 +805,7 @@ const sendDynamicRemarketingEvent = (eventName, manifestVariables, data, pageUrl
805
805
  };
806
806
 
807
807
  // eslint-disable-next-line @nx/enforce-module-boundaries
808
- const initGAds = (ID, consentData, executionContext, consentSkip) => {
808
+ const initGAds = (ID, consentData, executionContext, consentSkip, sdkUrl) => {
809
809
  var _a;
810
810
  if (!window.gtag) {
811
811
  return;
@@ -837,14 +837,16 @@ const initGAds = (ID, consentData, executionContext, consentSkip) => {
837
837
  window.gtag('js', new Date());
838
838
  const element = document.createElement('script');
839
839
  element.async = !0;
840
- element.src = `https://www.googletagmanager.com/gtag/js?id=${ID}`;
840
+ // Use the custom destination URL (e.g. Google Tag Gateway) verbatim if
841
+ // provided, otherwise fall back to the standard googletagmanager.com URL.
842
+ element.src = sdkUrl || `https://www.googletagmanager.com/gtag/js?id=${ID}`;
841
843
  const script = document.getElementsByTagName('script')[0];
842
844
  if (script && script.parentNode) {
843
845
  script.parentNode.insertBefore(element, script);
844
846
  }
845
847
  };
846
848
  const init = ({ manifest, consentData, executionContext, pageUrl, }) => {
847
- var _a, _b, _c, _d, _e, _f;
849
+ var _a, _b, _c, _d, _e, _f, _g;
848
850
  const shouldLoadSDK = ((_a = manifest === null || manifest === void 0 ? void 0 : manifest.variables) === null || _a === void 0 ? void 0 : _a['loadSDK']) === '1' ||
849
851
  ((_b = manifest === null || manifest === void 0 ? void 0 : manifest.variables) === null || _b === void 0 ? void 0 : _b['dynamicRemarketingEnabled']) === '1';
850
852
  if (typeof window === 'undefined' ||
@@ -871,13 +873,15 @@ const init = ({ manifest, consentData, executionContext, pageUrl, }) => {
871
873
  };
872
874
  if (!window.google_tag_manager ||
873
875
  !window.google_tag_manager[manifest.variables['tagId']]) {
874
- initGAds(manifest.variables['tagId'], consentData, executionContext, (_f = manifest.variables) === null || _f === void 0 ? void 0 : _f['consentSkip']);
876
+ initGAds(manifest.variables['tagId'], consentData, executionContext, (_f = manifest.variables) === null || _f === void 0 ? void 0 : _f['consentSkip'], (_g = manifest.variables) === null || _g === void 0 ? void 0 : _g['sdkUrl']);
875
877
  }
876
878
  if (window.gtag) {
877
879
  window.gtag('config', manifest.variables['tagId'], customConfig);
878
880
  }
879
881
  };
880
882
 
883
+ const keyPrefix = `_worker`;
884
+
881
885
  const getCookieValue = (key) => {
882
886
  var _a;
883
887
  try {
@@ -914,16 +918,67 @@ const parseCookies = (cookie) => {
914
918
  }));
915
919
  };
916
920
 
921
+ const initKey = `${keyPrefix}StoreMultiple`;
922
+ const getData = (destination, persistType, key = initKey) => {
923
+ let data;
924
+ if (persistType === 'session') {
925
+ data = getSession(key);
926
+ }
927
+ else {
928
+ data = getLocal(key);
929
+ }
930
+ return (data === null || data === void 0 ? void 0 : data[destination]) || {};
931
+ };
932
+ const getLocal = (key) => {
933
+ try {
934
+ if (!localStorage) {
935
+ return {};
936
+ }
937
+ const data = localStorage.getItem(key);
938
+ if (!data) {
939
+ return {};
940
+ }
941
+ return JSON.parse(data) || {};
942
+ }
943
+ catch {
944
+ return {};
945
+ }
946
+ };
947
+ const getSession = (key) => {
948
+ try {
949
+ if (!sessionStorage) {
950
+ return {};
951
+ }
952
+ const data = sessionStorage.getItem(key);
953
+ if (!data) {
954
+ return {};
955
+ }
956
+ return JSON.parse(data) || {};
957
+ }
958
+ catch {
959
+ return {};
960
+ }
961
+ };
962
+
917
963
  const getIsNewCustomerFlag = async (getData) => {
918
964
  const { isNewCustomer } = await new Promise((resolve) => getData(['isNewCustomer'], resolve));
919
965
  return isNewCustomer ? isNewCustomer === 'true' : undefined;
920
966
  };
967
+ // Reads the isNewCustomer flag already persisted in the browser's session KV
968
+ // (written by the `data` API call, which runs before the Purchase event). Lets
969
+ // callers use the local value and avoid a redundant edge round-trip; returns
970
+ // undefined when the value has not been stored yet so the caller can fall back.
971
+ const getIsNewCustomerFromBrowser = (destination) => {
972
+ const kv = getData(destination, 'session')['kv'];
973
+ const isNewCustomer = kv === null || kv === void 0 ? void 0 : kv['isNewCustomer'];
974
+ return isNewCustomer ? isNewCustomer === 'true' : undefined;
975
+ };
921
976
 
922
977
  const tag = ({ data, eventName, manifestVariables, destination, pageUrl, getEdgeData, }) => {
923
978
  var _a;
924
979
  const result = {
925
980
  isFired: false,
926
- sdkVersion: "1.63.1" ,
981
+ sdkVersion: "1.63.3" ,
927
982
  };
928
983
  if (!eventName || !window.gtag || !(manifestVariables === null || manifestVariables === void 0 ? void 0 : manifestVariables['tagId'])) {
929
984
  return result;
@@ -961,11 +1016,24 @@ const tag = ({ data, eventName, manifestVariables, destination, pageUrl, getEdge
961
1016
  (_a = window.gtag) === null || _a === void 0 ? void 0 : _a.call(window, 'event', 'conversion', conversionPayload);
962
1017
  };
963
1018
  if (eventName === 'Purchase' &&
964
- (manifestVariables === null || manifestVariables === void 0 ? void 0 : manifestVariables['newCustomerReportingEnabled']) === '1' &&
965
- getEdgeData) {
966
- getIsNewCustomerFlag(getEdgeData)
967
- .then(fireConversion)
968
- .catch(() => fireConversion());
1019
+ (manifestVariables === null || manifestVariables === void 0 ? void 0 : manifestVariables['newCustomerReportingEnabled']) === '1') {
1020
+ // Prefer the isNewCustomer flag already saved in the browser (e.g. by the
1021
+ // Shopify pixel's `data` call, which runs before Purchase). Only query the
1022
+ // edge when the browser value is missing.
1023
+ const browserValue = destination
1024
+ ? getIsNewCustomerFromBrowser(destination)
1025
+ : undefined;
1026
+ if (typeof browserValue === 'boolean') {
1027
+ fireConversion(browserValue);
1028
+ }
1029
+ else if (getEdgeData) {
1030
+ getIsNewCustomerFlag(getEdgeData)
1031
+ .then(fireConversion)
1032
+ .catch(() => fireConversion());
1033
+ }
1034
+ else {
1035
+ fireConversion();
1036
+ }
969
1037
  }
970
1038
  else {
971
1039
  fireConversion();
package/index.js CHANGED
@@ -806,7 +806,7 @@ var ProvidersGoogleAdsClicksSdk = (function () {
806
806
  };
807
807
 
808
808
  // eslint-disable-next-line @nx/enforce-module-boundaries
809
- const initGAds = (ID, consentData, executionContext, consentSkip) => {
809
+ const initGAds = (ID, consentData, executionContext, consentSkip, sdkUrl) => {
810
810
  var _a;
811
811
  if (!window.gtag) {
812
812
  return;
@@ -838,14 +838,16 @@ var ProvidersGoogleAdsClicksSdk = (function () {
838
838
  window.gtag('js', new Date());
839
839
  const element = document.createElement('script');
840
840
  element.async = !0;
841
- element.src = `https://www.googletagmanager.com/gtag/js?id=${ID}`;
841
+ // Use the custom destination URL (e.g. Google Tag Gateway) verbatim if
842
+ // provided, otherwise fall back to the standard googletagmanager.com URL.
843
+ element.src = sdkUrl || `https://www.googletagmanager.com/gtag/js?id=${ID}`;
842
844
  const script = document.getElementsByTagName('script')[0];
843
845
  if (script && script.parentNode) {
844
846
  script.parentNode.insertBefore(element, script);
845
847
  }
846
848
  };
847
849
  const init = ({ manifest, consentData, executionContext, pageUrl, }) => {
848
- var _a, _b, _c, _d, _e, _f;
850
+ var _a, _b, _c, _d, _e, _f, _g;
849
851
  const shouldLoadSDK = ((_a = manifest === null || manifest === void 0 ? void 0 : manifest.variables) === null || _a === void 0 ? void 0 : _a['loadSDK']) === '1' ||
850
852
  ((_b = manifest === null || manifest === void 0 ? void 0 : manifest.variables) === null || _b === void 0 ? void 0 : _b['dynamicRemarketingEnabled']) === '1';
851
853
  if (typeof window === 'undefined' ||
@@ -872,13 +874,15 @@ var ProvidersGoogleAdsClicksSdk = (function () {
872
874
  };
873
875
  if (!window.google_tag_manager ||
874
876
  !window.google_tag_manager[manifest.variables['tagId']]) {
875
- initGAds(manifest.variables['tagId'], consentData, executionContext, (_f = manifest.variables) === null || _f === void 0 ? void 0 : _f['consentSkip']);
877
+ initGAds(manifest.variables['tagId'], consentData, executionContext, (_f = manifest.variables) === null || _f === void 0 ? void 0 : _f['consentSkip'], (_g = manifest.variables) === null || _g === void 0 ? void 0 : _g['sdkUrl']);
876
878
  }
877
879
  if (window.gtag) {
878
880
  window.gtag('config', manifest.variables['tagId'], customConfig);
879
881
  }
880
882
  };
881
883
 
884
+ const keyPrefix = `_worker`;
885
+
882
886
  const getCookieValue = (key) => {
883
887
  var _a;
884
888
  try {
@@ -915,16 +919,67 @@ var ProvidersGoogleAdsClicksSdk = (function () {
915
919
  }));
916
920
  };
917
921
 
922
+ const initKey = `${keyPrefix}StoreMultiple`;
923
+ const getData = (destination, persistType, key = initKey) => {
924
+ let data;
925
+ if (persistType === 'session') {
926
+ data = getSession(key);
927
+ }
928
+ else {
929
+ data = getLocal(key);
930
+ }
931
+ return (data === null || data === void 0 ? void 0 : data[destination]) || {};
932
+ };
933
+ const getLocal = (key) => {
934
+ try {
935
+ if (!localStorage) {
936
+ return {};
937
+ }
938
+ const data = localStorage.getItem(key);
939
+ if (!data) {
940
+ return {};
941
+ }
942
+ return JSON.parse(data) || {};
943
+ }
944
+ catch {
945
+ return {};
946
+ }
947
+ };
948
+ const getSession = (key) => {
949
+ try {
950
+ if (!sessionStorage) {
951
+ return {};
952
+ }
953
+ const data = sessionStorage.getItem(key);
954
+ if (!data) {
955
+ return {};
956
+ }
957
+ return JSON.parse(data) || {};
958
+ }
959
+ catch {
960
+ return {};
961
+ }
962
+ };
963
+
918
964
  const getIsNewCustomerFlag = async (getData) => {
919
965
  const { isNewCustomer } = await new Promise((resolve) => getData(['isNewCustomer'], resolve));
920
966
  return isNewCustomer ? isNewCustomer === 'true' : undefined;
921
967
  };
968
+ // Reads the isNewCustomer flag already persisted in the browser's session KV
969
+ // (written by the `data` API call, which runs before the Purchase event). Lets
970
+ // callers use the local value and avoid a redundant edge round-trip; returns
971
+ // undefined when the value has not been stored yet so the caller can fall back.
972
+ const getIsNewCustomerFromBrowser = (destination) => {
973
+ const kv = getData(destination, 'session')['kv'];
974
+ const isNewCustomer = kv === null || kv === void 0 ? void 0 : kv['isNewCustomer'];
975
+ return isNewCustomer ? isNewCustomer === 'true' : undefined;
976
+ };
922
977
 
923
978
  const tag = ({ data, eventName, manifestVariables, destination, pageUrl, getEdgeData, }) => {
924
979
  var _a;
925
980
  const result = {
926
981
  isFired: false,
927
- sdkVersion: "1.63.1" ,
982
+ sdkVersion: "1.63.3" ,
928
983
  };
929
984
  if (!eventName || !window.gtag || !(manifestVariables === null || manifestVariables === void 0 ? void 0 : manifestVariables['tagId'])) {
930
985
  return result;
@@ -962,11 +1017,24 @@ var ProvidersGoogleAdsClicksSdk = (function () {
962
1017
  (_a = window.gtag) === null || _a === void 0 ? void 0 : _a.call(window, 'event', 'conversion', conversionPayload);
963
1018
  };
964
1019
  if (eventName === 'Purchase' &&
965
- (manifestVariables === null || manifestVariables === void 0 ? void 0 : manifestVariables['newCustomerReportingEnabled']) === '1' &&
966
- getEdgeData) {
967
- getIsNewCustomerFlag(getEdgeData)
968
- .then(fireConversion)
969
- .catch(() => fireConversion());
1020
+ (manifestVariables === null || manifestVariables === void 0 ? void 0 : manifestVariables['newCustomerReportingEnabled']) === '1') {
1021
+ // Prefer the isNewCustomer flag already saved in the browser (e.g. by the
1022
+ // Shopify pixel's `data` call, which runs before Purchase). Only query the
1023
+ // edge when the browser value is missing.
1024
+ const browserValue = destination
1025
+ ? getIsNewCustomerFromBrowser(destination)
1026
+ : undefined;
1027
+ if (typeof browserValue === 'boolean') {
1028
+ fireConversion(browserValue);
1029
+ }
1030
+ else if (getEdgeData) {
1031
+ getIsNewCustomerFlag(getEdgeData)
1032
+ .then(fireConversion)
1033
+ .catch(() => fireConversion());
1034
+ }
1035
+ else {
1036
+ fireConversion();
1037
+ }
970
1038
  }
971
1039
  else {
972
1040
  fireConversion();
package/index.mjs CHANGED
@@ -803,7 +803,7 @@ const sendDynamicRemarketingEvent = (eventName, manifestVariables, data, pageUrl
803
803
  };
804
804
 
805
805
  // eslint-disable-next-line @nx/enforce-module-boundaries
806
- const initGAds = (ID, consentData, executionContext, consentSkip) => {
806
+ const initGAds = (ID, consentData, executionContext, consentSkip, sdkUrl) => {
807
807
  var _a;
808
808
  if (!window.gtag) {
809
809
  return;
@@ -835,14 +835,16 @@ const initGAds = (ID, consentData, executionContext, consentSkip) => {
835
835
  window.gtag('js', new Date());
836
836
  const element = document.createElement('script');
837
837
  element.async = !0;
838
- element.src = `https://www.googletagmanager.com/gtag/js?id=${ID}`;
838
+ // Use the custom destination URL (e.g. Google Tag Gateway) verbatim if
839
+ // provided, otherwise fall back to the standard googletagmanager.com URL.
840
+ element.src = sdkUrl || `https://www.googletagmanager.com/gtag/js?id=${ID}`;
839
841
  const script = document.getElementsByTagName('script')[0];
840
842
  if (script && script.parentNode) {
841
843
  script.parentNode.insertBefore(element, script);
842
844
  }
843
845
  };
844
846
  const init = ({ manifest, consentData, executionContext, pageUrl, }) => {
845
- var _a, _b, _c, _d, _e, _f;
847
+ var _a, _b, _c, _d, _e, _f, _g;
846
848
  const shouldLoadSDK = ((_a = manifest === null || manifest === void 0 ? void 0 : manifest.variables) === null || _a === void 0 ? void 0 : _a['loadSDK']) === '1' ||
847
849
  ((_b = manifest === null || manifest === void 0 ? void 0 : manifest.variables) === null || _b === void 0 ? void 0 : _b['dynamicRemarketingEnabled']) === '1';
848
850
  if (typeof window === 'undefined' ||
@@ -869,13 +871,15 @@ const init = ({ manifest, consentData, executionContext, pageUrl, }) => {
869
871
  };
870
872
  if (!window.google_tag_manager ||
871
873
  !window.google_tag_manager[manifest.variables['tagId']]) {
872
- initGAds(manifest.variables['tagId'], consentData, executionContext, (_f = manifest.variables) === null || _f === void 0 ? void 0 : _f['consentSkip']);
874
+ initGAds(manifest.variables['tagId'], consentData, executionContext, (_f = manifest.variables) === null || _f === void 0 ? void 0 : _f['consentSkip'], (_g = manifest.variables) === null || _g === void 0 ? void 0 : _g['sdkUrl']);
873
875
  }
874
876
  if (window.gtag) {
875
877
  window.gtag('config', manifest.variables['tagId'], customConfig);
876
878
  }
877
879
  };
878
880
 
881
+ const keyPrefix = `_worker`;
882
+
879
883
  const getCookieValue = (key) => {
880
884
  var _a;
881
885
  try {
@@ -912,16 +916,67 @@ const parseCookies = (cookie) => {
912
916
  }));
913
917
  };
914
918
 
919
+ const initKey = `${keyPrefix}StoreMultiple`;
920
+ const getData = (destination, persistType, key = initKey) => {
921
+ let data;
922
+ if (persistType === 'session') {
923
+ data = getSession(key);
924
+ }
925
+ else {
926
+ data = getLocal(key);
927
+ }
928
+ return (data === null || data === void 0 ? void 0 : data[destination]) || {};
929
+ };
930
+ const getLocal = (key) => {
931
+ try {
932
+ if (!localStorage) {
933
+ return {};
934
+ }
935
+ const data = localStorage.getItem(key);
936
+ if (!data) {
937
+ return {};
938
+ }
939
+ return JSON.parse(data) || {};
940
+ }
941
+ catch {
942
+ return {};
943
+ }
944
+ };
945
+ const getSession = (key) => {
946
+ try {
947
+ if (!sessionStorage) {
948
+ return {};
949
+ }
950
+ const data = sessionStorage.getItem(key);
951
+ if (!data) {
952
+ return {};
953
+ }
954
+ return JSON.parse(data) || {};
955
+ }
956
+ catch {
957
+ return {};
958
+ }
959
+ };
960
+
915
961
  const getIsNewCustomerFlag = async (getData) => {
916
962
  const { isNewCustomer } = await new Promise((resolve) => getData(['isNewCustomer'], resolve));
917
963
  return isNewCustomer ? isNewCustomer === 'true' : undefined;
918
964
  };
965
+ // Reads the isNewCustomer flag already persisted in the browser's session KV
966
+ // (written by the `data` API call, which runs before the Purchase event). Lets
967
+ // callers use the local value and avoid a redundant edge round-trip; returns
968
+ // undefined when the value has not been stored yet so the caller can fall back.
969
+ const getIsNewCustomerFromBrowser = (destination) => {
970
+ const kv = getData(destination, 'session')['kv'];
971
+ const isNewCustomer = kv === null || kv === void 0 ? void 0 : kv['isNewCustomer'];
972
+ return isNewCustomer ? isNewCustomer === 'true' : undefined;
973
+ };
919
974
 
920
975
  const tag = ({ data, eventName, manifestVariables, destination, pageUrl, getEdgeData, }) => {
921
976
  var _a;
922
977
  const result = {
923
978
  isFired: false,
924
- sdkVersion: "1.63.1" ,
979
+ sdkVersion: "1.63.3" ,
925
980
  };
926
981
  if (!eventName || !window.gtag || !(manifestVariables === null || manifestVariables === void 0 ? void 0 : manifestVariables['tagId'])) {
927
982
  return result;
@@ -959,11 +1014,24 @@ const tag = ({ data, eventName, manifestVariables, destination, pageUrl, getEdge
959
1014
  (_a = window.gtag) === null || _a === void 0 ? void 0 : _a.call(window, 'event', 'conversion', conversionPayload);
960
1015
  };
961
1016
  if (eventName === 'Purchase' &&
962
- (manifestVariables === null || manifestVariables === void 0 ? void 0 : manifestVariables['newCustomerReportingEnabled']) === '1' &&
963
- getEdgeData) {
964
- getIsNewCustomerFlag(getEdgeData)
965
- .then(fireConversion)
966
- .catch(() => fireConversion());
1017
+ (manifestVariables === null || manifestVariables === void 0 ? void 0 : manifestVariables['newCustomerReportingEnabled']) === '1') {
1018
+ // Prefer the isNewCustomer flag already saved in the browser (e.g. by the
1019
+ // Shopify pixel's `data` call, which runs before Purchase). Only query the
1020
+ // edge when the browser value is missing.
1021
+ const browserValue = destination
1022
+ ? getIsNewCustomerFromBrowser(destination)
1023
+ : undefined;
1024
+ if (typeof browserValue === 'boolean') {
1025
+ fireConversion(browserValue);
1026
+ }
1027
+ else if (getEdgeData) {
1028
+ getIsNewCustomerFlag(getEdgeData)
1029
+ .then(fireConversion)
1030
+ .catch(() => fireConversion());
1031
+ }
1032
+ else {
1033
+ fireConversion();
1034
+ }
967
1035
  }
968
1036
  else {
969
1037
  fireConversion();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blotoutio/providers-google-ads-clicks-sdk",
3
- "version": "1.63.1",
3
+ "version": "1.63.3",
4
4
  "description": "Google Ads Browser SDK for EdgeTag",
5
5
  "author": "Blotout",
6
6
  "license": "MIT",