@blotoutio/providers-google-ads-clicks-sdk 1.55.1 → 1.56.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 (4) hide show
  1. package/index.cjs.js +33 -12
  2. package/index.js +33 -12
  3. package/index.mjs +33 -12
  4. package/package.json +1 -1
package/index.cjs.js CHANGED
@@ -600,7 +600,7 @@ const getConversionLabel = (eventName, manifestVariables) => {
600
600
  const mapping = mappings.find((mappingItem) => mappingItem.eventName === eventName);
601
601
  return mapping === null || mapping === void 0 ? void 0 : mapping.browserConversionLabel;
602
602
  };
603
- const getEventData = (data) => {
603
+ const getEventData = (data, isNewCustomer) => {
604
604
  const eventData = {};
605
605
  if (!data) {
606
606
  return eventData;
@@ -614,6 +614,9 @@ const getEventData = (data) => {
614
614
  if (data['orderId']) {
615
615
  eventData.transaction_id = data['orderId'];
616
616
  }
617
+ if (typeof isNewCustomer === 'boolean') {
618
+ eventData.new_customer = isNewCustomer;
619
+ }
617
620
  return eventData;
618
621
  };
619
622
  const getCartData = (variables, data) => {
@@ -911,11 +914,16 @@ const parseCookies = (cookie) => {
911
914
  }));
912
915
  };
913
916
 
914
- const tag = ({ data, eventName, manifestVariables, destination, pageUrl, }) => {
917
+ const getIsNewCustomerFlag = async (getData) => {
918
+ const { isNewCustomer } = await new Promise((resolve) => getData(['isNewCustomer'], resolve));
919
+ return isNewCustomer ? isNewCustomer === 'true' : undefined;
920
+ };
921
+
922
+ const tag = ({ data, eventName, manifestVariables, destination, pageUrl, getEdgeData, }) => {
915
923
  var _a;
916
924
  const result = {
917
925
  isFired: false,
918
- sdkVersion: "1.55.1" ,
926
+ sdkVersion: "1.56.0" ,
919
927
  };
920
928
  if (!eventName || !window.gtag || !(manifestVariables === null || manifestVariables === void 0 ? void 0 : manifestVariables['tagId'])) {
921
929
  return result;
@@ -937,18 +945,31 @@ const tag = ({ data, eventName, manifestVariables, destination, pageUrl, }) => {
937
945
  destination) {
938
946
  window.gtag('set', 'user_data', getUserData(destination));
939
947
  }
940
- const eventData = getEventData(data);
941
948
  const cartData = getCartData(manifestVariables, data);
942
- const conversionPayload = {
943
- send_to: conversionLabel,
944
- ...eventData,
945
- ...cartData,
946
- app: 'blotout',
949
+ const fireConversion = (isNewCustomer) => {
950
+ var _a;
951
+ const eventData = getEventData(data, isNewCustomer);
952
+ const conversionPayload = {
953
+ send_to: conversionLabel,
954
+ ...eventData,
955
+ ...cartData,
956
+ app: 'blotout',
957
+ };
958
+ if (resolvedPageUrl) {
959
+ conversionPayload['page_location'] = resolvedPageUrl;
960
+ }
961
+ (_a = window.gtag) === null || _a === void 0 ? void 0 : _a.call(window, 'event', 'conversion', conversionPayload);
947
962
  };
948
- if (resolvedPageUrl) {
949
- conversionPayload['page_location'] = resolvedPageUrl;
963
+ 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());
969
+ }
970
+ else {
971
+ fireConversion();
950
972
  }
951
- window.gtag('event', 'conversion', conversionPayload);
952
973
  result.isFired = true;
953
974
  }
954
975
  }
package/index.js CHANGED
@@ -601,7 +601,7 @@ var ProvidersGoogleAdsClicksSdk = (function () {
601
601
  const mapping = mappings.find((mappingItem) => mappingItem.eventName === eventName);
602
602
  return mapping === null || mapping === void 0 ? void 0 : mapping.browserConversionLabel;
603
603
  };
604
- const getEventData = (data) => {
604
+ const getEventData = (data, isNewCustomer) => {
605
605
  const eventData = {};
606
606
  if (!data) {
607
607
  return eventData;
@@ -615,6 +615,9 @@ var ProvidersGoogleAdsClicksSdk = (function () {
615
615
  if (data['orderId']) {
616
616
  eventData.transaction_id = data['orderId'];
617
617
  }
618
+ if (typeof isNewCustomer === 'boolean') {
619
+ eventData.new_customer = isNewCustomer;
620
+ }
618
621
  return eventData;
619
622
  };
620
623
  const getCartData = (variables, data) => {
@@ -912,11 +915,16 @@ var ProvidersGoogleAdsClicksSdk = (function () {
912
915
  }));
913
916
  };
914
917
 
915
- const tag = ({ data, eventName, manifestVariables, destination, pageUrl, }) => {
918
+ const getIsNewCustomerFlag = async (getData) => {
919
+ const { isNewCustomer } = await new Promise((resolve) => getData(['isNewCustomer'], resolve));
920
+ return isNewCustomer ? isNewCustomer === 'true' : undefined;
921
+ };
922
+
923
+ const tag = ({ data, eventName, manifestVariables, destination, pageUrl, getEdgeData, }) => {
916
924
  var _a;
917
925
  const result = {
918
926
  isFired: false,
919
- sdkVersion: "1.55.1" ,
927
+ sdkVersion: "1.56.0" ,
920
928
  };
921
929
  if (!eventName || !window.gtag || !(manifestVariables === null || manifestVariables === void 0 ? void 0 : manifestVariables['tagId'])) {
922
930
  return result;
@@ -938,18 +946,31 @@ var ProvidersGoogleAdsClicksSdk = (function () {
938
946
  destination) {
939
947
  window.gtag('set', 'user_data', getUserData(destination));
940
948
  }
941
- const eventData = getEventData(data);
942
949
  const cartData = getCartData(manifestVariables, data);
943
- const conversionPayload = {
944
- send_to: conversionLabel,
945
- ...eventData,
946
- ...cartData,
947
- app: 'blotout',
950
+ const fireConversion = (isNewCustomer) => {
951
+ var _a;
952
+ const eventData = getEventData(data, isNewCustomer);
953
+ const conversionPayload = {
954
+ send_to: conversionLabel,
955
+ ...eventData,
956
+ ...cartData,
957
+ app: 'blotout',
958
+ };
959
+ if (resolvedPageUrl) {
960
+ conversionPayload['page_location'] = resolvedPageUrl;
961
+ }
962
+ (_a = window.gtag) === null || _a === void 0 ? void 0 : _a.call(window, 'event', 'conversion', conversionPayload);
948
963
  };
949
- if (resolvedPageUrl) {
950
- conversionPayload['page_location'] = resolvedPageUrl;
964
+ 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());
970
+ }
971
+ else {
972
+ fireConversion();
951
973
  }
952
- window.gtag('event', 'conversion', conversionPayload);
953
974
  result.isFired = true;
954
975
  }
955
976
  }
package/index.mjs CHANGED
@@ -598,7 +598,7 @@ const getConversionLabel = (eventName, manifestVariables) => {
598
598
  const mapping = mappings.find((mappingItem) => mappingItem.eventName === eventName);
599
599
  return mapping === null || mapping === void 0 ? void 0 : mapping.browserConversionLabel;
600
600
  };
601
- const getEventData = (data) => {
601
+ const getEventData = (data, isNewCustomer) => {
602
602
  const eventData = {};
603
603
  if (!data) {
604
604
  return eventData;
@@ -612,6 +612,9 @@ const getEventData = (data) => {
612
612
  if (data['orderId']) {
613
613
  eventData.transaction_id = data['orderId'];
614
614
  }
615
+ if (typeof isNewCustomer === 'boolean') {
616
+ eventData.new_customer = isNewCustomer;
617
+ }
615
618
  return eventData;
616
619
  };
617
620
  const getCartData = (variables, data) => {
@@ -909,11 +912,16 @@ const parseCookies = (cookie) => {
909
912
  }));
910
913
  };
911
914
 
912
- const tag = ({ data, eventName, manifestVariables, destination, pageUrl, }) => {
915
+ const getIsNewCustomerFlag = async (getData) => {
916
+ const { isNewCustomer } = await new Promise((resolve) => getData(['isNewCustomer'], resolve));
917
+ return isNewCustomer ? isNewCustomer === 'true' : undefined;
918
+ };
919
+
920
+ const tag = ({ data, eventName, manifestVariables, destination, pageUrl, getEdgeData, }) => {
913
921
  var _a;
914
922
  const result = {
915
923
  isFired: false,
916
- sdkVersion: "1.55.1" ,
924
+ sdkVersion: "1.56.0" ,
917
925
  };
918
926
  if (!eventName || !window.gtag || !(manifestVariables === null || manifestVariables === void 0 ? void 0 : manifestVariables['tagId'])) {
919
927
  return result;
@@ -935,18 +943,31 @@ const tag = ({ data, eventName, manifestVariables, destination, pageUrl, }) => {
935
943
  destination) {
936
944
  window.gtag('set', 'user_data', getUserData(destination));
937
945
  }
938
- const eventData = getEventData(data);
939
946
  const cartData = getCartData(manifestVariables, data);
940
- const conversionPayload = {
941
- send_to: conversionLabel,
942
- ...eventData,
943
- ...cartData,
944
- app: 'blotout',
947
+ const fireConversion = (isNewCustomer) => {
948
+ var _a;
949
+ const eventData = getEventData(data, isNewCustomer);
950
+ const conversionPayload = {
951
+ send_to: conversionLabel,
952
+ ...eventData,
953
+ ...cartData,
954
+ app: 'blotout',
955
+ };
956
+ if (resolvedPageUrl) {
957
+ conversionPayload['page_location'] = resolvedPageUrl;
958
+ }
959
+ (_a = window.gtag) === null || _a === void 0 ? void 0 : _a.call(window, 'event', 'conversion', conversionPayload);
945
960
  };
946
- if (resolvedPageUrl) {
947
- conversionPayload['page_location'] = resolvedPageUrl;
961
+ 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());
967
+ }
968
+ else {
969
+ fireConversion();
948
970
  }
949
- window.gtag('event', 'conversion', conversionPayload);
950
971
  result.isFired = true;
951
972
  }
952
973
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blotoutio/providers-google-ads-clicks-sdk",
3
- "version": "1.55.1",
3
+ "version": "1.56.0",
4
4
  "description": "Google Ads Browser SDK for EdgeTag",
5
5
  "author": "Blotout",
6
6
  "license": "MIT",