@blotoutio/providers-google-ads-clicks-sdk 0.55.2 → 0.57.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/index.cjs.js CHANGED
@@ -103,6 +103,16 @@ const init = ({ manifest, executionContext }) => {
103
103
  }
104
104
  };
105
105
 
106
+ const getIdentifierValue = (identifier, contentItem) => {
107
+ let identifierValue = identifier.trim();
108
+ if (!contentItem) {
109
+ return identifierValue;
110
+ }
111
+ identifierValue = identifierValue.replaceAll('{productId}', contentItem.id);
112
+ identifierValue = identifierValue.replaceAll('{variantId}', contentItem.variantId || '');
113
+ identifierValue = identifierValue.replaceAll('{sku}', contentItem.sku || '');
114
+ return identifierValue;
115
+ };
106
116
  const getConversionLabel = (eventName, manifestVariables) => {
107
117
  if (!manifestVariables) {
108
118
  return '';
@@ -134,6 +144,23 @@ const getEventData = (data) => {
134
144
  }
135
145
  return eventData;
136
146
  };
147
+ const getCartData = (variables, data) => {
148
+ const cartData = {};
149
+ const merchantId = parseInt(variables['merchantId']);
150
+ if (!isNaN(merchantId)) {
151
+ cartData.aw_merchant_id = merchantId;
152
+ }
153
+ if (data && data['contents'] && Array.isArray(data['contents'])) {
154
+ cartData.items = data['contents'].map((content) => {
155
+ return {
156
+ id: getIdentifierValue(variables['identifierFormat'], content),
157
+ price: content.item_price,
158
+ quantity: content.quantity,
159
+ };
160
+ });
161
+ }
162
+ return cartData;
163
+ };
137
164
  const handleTag = ({ data, eventName, manifestVariables, }) => {
138
165
  if (!eventName ||
139
166
  !window.gtag ||
@@ -143,12 +170,14 @@ const handleTag = ({ data, eventName, manifestVariables, }) => {
143
170
  }
144
171
  const conversionLabel = getConversionLabel(eventName, manifestVariables);
145
172
  const eventData = getEventData(data);
173
+ const cartData = getCartData(manifestVariables, data);
146
174
  if (!conversionLabel) {
147
175
  return;
148
176
  }
149
177
  window.gtag('event', 'conversion', {
150
178
  send_to: conversionLabel,
151
179
  ...eventData,
180
+ ...cartData,
152
181
  app: 'blotout',
153
182
  });
154
183
  };
@@ -184,7 +213,7 @@ const tag = ({ data, eventName, manifestVariables, eventId }) => {
184
213
  }
185
214
  return {
186
215
  loaded: isLoaded,
187
- sdkVersion: "0.55.2" ,
216
+ sdkVersion: "0.57.0" ,
188
217
  };
189
218
  };
190
219
 
package/index.js CHANGED
@@ -104,6 +104,16 @@ var ProvidersGoogleAdsClicksSdk = (function () {
104
104
  }
105
105
  };
106
106
 
107
+ const getIdentifierValue = (identifier, contentItem) => {
108
+ let identifierValue = identifier.trim();
109
+ if (!contentItem) {
110
+ return identifierValue;
111
+ }
112
+ identifierValue = identifierValue.replaceAll('{productId}', contentItem.id);
113
+ identifierValue = identifierValue.replaceAll('{variantId}', contentItem.variantId || '');
114
+ identifierValue = identifierValue.replaceAll('{sku}', contentItem.sku || '');
115
+ return identifierValue;
116
+ };
107
117
  const getConversionLabel = (eventName, manifestVariables) => {
108
118
  if (!manifestVariables) {
109
119
  return '';
@@ -135,6 +145,23 @@ var ProvidersGoogleAdsClicksSdk = (function () {
135
145
  }
136
146
  return eventData;
137
147
  };
148
+ const getCartData = (variables, data) => {
149
+ const cartData = {};
150
+ const merchantId = parseInt(variables['merchantId']);
151
+ if (!isNaN(merchantId)) {
152
+ cartData.aw_merchant_id = merchantId;
153
+ }
154
+ if (data && data['contents'] && Array.isArray(data['contents'])) {
155
+ cartData.items = data['contents'].map((content) => {
156
+ return {
157
+ id: getIdentifierValue(variables['identifierFormat'], content),
158
+ price: content.item_price,
159
+ quantity: content.quantity,
160
+ };
161
+ });
162
+ }
163
+ return cartData;
164
+ };
138
165
  const handleTag = ({ data, eventName, manifestVariables, }) => {
139
166
  if (!eventName ||
140
167
  !window.gtag ||
@@ -144,12 +171,14 @@ var ProvidersGoogleAdsClicksSdk = (function () {
144
171
  }
145
172
  const conversionLabel = getConversionLabel(eventName, manifestVariables);
146
173
  const eventData = getEventData(data);
174
+ const cartData = getCartData(manifestVariables, data);
147
175
  if (!conversionLabel) {
148
176
  return;
149
177
  }
150
178
  window.gtag('event', 'conversion', {
151
179
  send_to: conversionLabel,
152
180
  ...eventData,
181
+ ...cartData,
153
182
  app: 'blotout',
154
183
  });
155
184
  };
@@ -185,7 +214,7 @@ var ProvidersGoogleAdsClicksSdk = (function () {
185
214
  }
186
215
  return {
187
216
  loaded: isLoaded,
188
- sdkVersion: "0.55.2" ,
217
+ sdkVersion: "0.57.0" ,
189
218
  };
190
219
  };
191
220
 
package/index.mjs CHANGED
@@ -101,6 +101,16 @@ const init = ({ manifest, executionContext }) => {
101
101
  }
102
102
  };
103
103
 
104
+ const getIdentifierValue = (identifier, contentItem) => {
105
+ let identifierValue = identifier.trim();
106
+ if (!contentItem) {
107
+ return identifierValue;
108
+ }
109
+ identifierValue = identifierValue.replaceAll('{productId}', contentItem.id);
110
+ identifierValue = identifierValue.replaceAll('{variantId}', contentItem.variantId || '');
111
+ identifierValue = identifierValue.replaceAll('{sku}', contentItem.sku || '');
112
+ return identifierValue;
113
+ };
104
114
  const getConversionLabel = (eventName, manifestVariables) => {
105
115
  if (!manifestVariables) {
106
116
  return '';
@@ -132,6 +142,23 @@ const getEventData = (data) => {
132
142
  }
133
143
  return eventData;
134
144
  };
145
+ const getCartData = (variables, data) => {
146
+ const cartData = {};
147
+ const merchantId = parseInt(variables['merchantId']);
148
+ if (!isNaN(merchantId)) {
149
+ cartData.aw_merchant_id = merchantId;
150
+ }
151
+ if (data && data['contents'] && Array.isArray(data['contents'])) {
152
+ cartData.items = data['contents'].map((content) => {
153
+ return {
154
+ id: getIdentifierValue(variables['identifierFormat'], content),
155
+ price: content.item_price,
156
+ quantity: content.quantity,
157
+ };
158
+ });
159
+ }
160
+ return cartData;
161
+ };
135
162
  const handleTag = ({ data, eventName, manifestVariables, }) => {
136
163
  if (!eventName ||
137
164
  !window.gtag ||
@@ -141,12 +168,14 @@ const handleTag = ({ data, eventName, manifestVariables, }) => {
141
168
  }
142
169
  const conversionLabel = getConversionLabel(eventName, manifestVariables);
143
170
  const eventData = getEventData(data);
171
+ const cartData = getCartData(manifestVariables, data);
144
172
  if (!conversionLabel) {
145
173
  return;
146
174
  }
147
175
  window.gtag('event', 'conversion', {
148
176
  send_to: conversionLabel,
149
177
  ...eventData,
178
+ ...cartData,
150
179
  app: 'blotout',
151
180
  });
152
181
  };
@@ -182,7 +211,7 @@ const tag = ({ data, eventName, manifestVariables, eventId }) => {
182
211
  }
183
212
  return {
184
213
  loaded: isLoaded,
185
- sdkVersion: "0.55.2" ,
214
+ sdkVersion: "0.57.0" ,
186
215
  };
187
216
  };
188
217
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blotoutio/providers-google-ads-clicks-sdk",
3
- "version": "0.55.2",
3
+ "version": "0.57.0",
4
4
  "description": "Google Ads Browser SDK for EdgeTag",
5
5
  "author": "Blotout",
6
6
  "license": "MIT",