@constructor-io/constructorio-client-javascript 2.43.0 → 2.44.1
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/lib/constructorio.js +2 -1
- package/lib/modules/tracker.js +6 -2
- package/lib/types/index.d.ts +5 -0
- package/lib/types/tracker.d.ts +2 -2
- package/lib/utils/helpers.js +15 -0
- package/package.json +1 -1
package/lib/constructorio.js
CHANGED
|
@@ -107,10 +107,11 @@ var ConstructorIO = /*#__PURE__*/function () {
|
|
|
107
107
|
throw new Error('clientId is a required user parameter of type string');
|
|
108
108
|
}
|
|
109
109
|
}
|
|
110
|
+
var normalizedServiceUrl = serviceUrl && serviceUrl.replace(/\/$/, '');
|
|
110
111
|
this.options = {
|
|
111
112
|
apiKey: apiKey,
|
|
112
113
|
version: versionFromOptions || versionFromGlobal || computePackageVersion(),
|
|
113
|
-
serviceUrl:
|
|
114
|
+
serviceUrl: helpers.addHTTPSToString(normalizedServiceUrl) || 'https://ac.cnstrc.com',
|
|
114
115
|
quizzesServiceUrl: quizzesServiceUrl && quizzesServiceUrl.replace(/\/$/, '') || 'https://quizzes.cnstrc.com',
|
|
115
116
|
sessionId: sessionId || session_id,
|
|
116
117
|
clientId: clientId || client_id,
|
package/lib/modules/tracker.js
CHANGED
|
@@ -1054,7 +1054,11 @@ var Tracker = /*#__PURE__*/function () {
|
|
|
1054
1054
|
*
|
|
1055
1055
|
* @function trackPurchase
|
|
1056
1056
|
* @param {object} parameters - Additional parameters to be sent with request
|
|
1057
|
-
* @param {
|
|
1057
|
+
* @param {Array.<{itemId: string | undefined,
|
|
1058
|
+
* variationId: string | undefined,
|
|
1059
|
+
* itemName: string | undefined,
|
|
1060
|
+
* count: number | undefined,
|
|
1061
|
+
* price: number | undefined}>} parameters.items - List of product item objects
|
|
1058
1062
|
* @param {number} parameters.revenue - The subtotal (excluding taxes, shipping, etc.) of the entire order
|
|
1059
1063
|
* @param {string} [parameters.orderId] - Unique order identifier
|
|
1060
1064
|
* @param {string} [parameters.section="Products"] - Index section
|
|
@@ -1066,7 +1070,7 @@ var Tracker = /*#__PURE__*/function () {
|
|
|
1066
1070
|
* @example
|
|
1067
1071
|
* constructorio.tracker.trackPurchase(
|
|
1068
1072
|
* {
|
|
1069
|
-
* items: [{ itemId: 'KMH876' }, { itemId: 'KMH140' }],
|
|
1073
|
+
* items: [{ itemId: 'KMH876', price: 1, count: 1}, { itemId: 'KMH140', price: 1, count: 1s }],
|
|
1070
1074
|
* revenue: 12.00,
|
|
1071
1075
|
* orderId: 'OUNXBG2HMA',
|
|
1072
1076
|
* section: 'Products',
|
package/lib/types/index.d.ts
CHANGED
package/lib/types/tracker.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import EventEmitter = require('events');
|
|
2
|
-
import { ConstructorClientOptions, ItemTracked, NetworkParameters } from '.';
|
|
2
|
+
import { ConstructorClientOptions, ItemTracked, ItemTrackedPurchase, NetworkParameters } from '.';
|
|
3
3
|
import RequestQueue = require('../utils/request-queue');
|
|
4
4
|
|
|
5
5
|
export default Tracker;
|
|
@@ -114,7 +114,7 @@ declare class Tracker {
|
|
|
114
114
|
|
|
115
115
|
trackPurchase(
|
|
116
116
|
parameters: {
|
|
117
|
-
items:
|
|
117
|
+
items: ItemTrackedPurchase[];
|
|
118
118
|
revenue: number;
|
|
119
119
|
orderId?: string;
|
|
120
120
|
section?: string;
|
package/lib/utils/helpers.js
CHANGED
|
@@ -220,6 +220,21 @@ var utils = {
|
|
|
220
220
|
// do nothing
|
|
221
221
|
}
|
|
222
222
|
return obfuscatedUrl;
|
|
223
|
+
},
|
|
224
|
+
addHTTPSToString: function addHTTPSToString(url) {
|
|
225
|
+
if (typeof url !== 'string') {
|
|
226
|
+
return null;
|
|
227
|
+
}
|
|
228
|
+
var doesUrlIncludeHTTPS = url.startsWith('https://');
|
|
229
|
+
var doesUrlStartWithHTTP = url.startsWith('http://');
|
|
230
|
+
if (!doesUrlIncludeHTTPS && doesUrlStartWithHTTP) {
|
|
231
|
+
return url.replace('http', 'https');
|
|
232
|
+
}
|
|
233
|
+
if (!doesUrlStartWithHTTP && !doesUrlIncludeHTTPS) {
|
|
234
|
+
var urlWithHttps = "https://".concat(url);
|
|
235
|
+
return urlWithHttps;
|
|
236
|
+
}
|
|
237
|
+
return url;
|
|
223
238
|
}
|
|
224
239
|
};
|
|
225
240
|
module.exports = utils;
|