@constructor-io/constructorio-client-javascript 2.34.7 → 2.34.8

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.
@@ -1235,6 +1235,433 @@ var Tracker = /*#__PURE__*/function () {
1235
1235
  this.requests.send();
1236
1236
  return new Error('A parameters object with an "item_id" property is required.');
1237
1237
  }
1238
+ /**
1239
+ * Send quiz results loaded event to API
1240
+ *
1241
+ * @function trackQuizResultsLoaded
1242
+ * @param {object} parameters - Additional parameters to be sent with request
1243
+ * @param {string} parameters.quiz_id - Quiz identifier
1244
+ * @param {string} parameters.quiz_version_id - Quiz version identifier
1245
+ * @param {string} parameters.quiz_session_id - Quiz session identifier associated with this conversion event
1246
+ * @param {string} parameters.url - Current page url
1247
+ * @param {string} [parameters.section='Products'] - Index section
1248
+ * @param {number} [parameters.result_count] - Total number of results
1249
+ * @param {number} [parameters.result_page] - The page of the results
1250
+ * @param {string} [parameters.result_id] - Quiz result identifier (returned in response from Constructor)
1251
+ * @param {object} [networkParameters] - Parameters relevant to the network request
1252
+ * @param {number} [networkParameters.timeout] - Request timeout (in milliseconds)
1253
+ * @returns {(true|Error)}
1254
+ * @description User viewed a quiz results page
1255
+ * @example
1256
+ * constructorio.tracker.trackQuizResultsLoaded(
1257
+ * {
1258
+ * quiz_id: 'coffee-quiz',
1259
+ * quiz_version_id: '1231244',
1260
+ * quiz_session_id: '3123',
1261
+ * url: 'www.example.com',
1262
+ * result_count: 167,
1263
+ * },
1264
+ * );
1265
+ */
1266
+
1267
+ }, {
1268
+ key: "trackQuizResultsLoaded",
1269
+ value: function trackQuizResultsLoaded(parameters) {
1270
+ var networkParameters = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
1271
+
1272
+ // Ensure parameters are provided (required)
1273
+ if (parameters && (0, _typeof2["default"])(parameters) === 'object' && !Array.isArray(parameters)) {
1274
+ var requestPath = "".concat(this.options.serviceUrl, "/v2/behavioral_action/quiz_result_load?");
1275
+ var quiz_id = parameters.quiz_id,
1276
+ quiz_version_id = parameters.quiz_version_id,
1277
+ quiz_session_id = parameters.quiz_session_id,
1278
+ url = parameters.url,
1279
+ _parameters$section2 = parameters.section,
1280
+ section = _parameters$section2 === void 0 ? 'Products' : _parameters$section2,
1281
+ result_count = parameters.result_count,
1282
+ result_id = parameters.result_id,
1283
+ result_page = parameters.result_page;
1284
+ var queryParams = {};
1285
+ var bodyParams = {};
1286
+
1287
+ if (typeof quiz_id !== 'string') {
1288
+ return new Error('"quiz_id" is a required parameter of type string');
1289
+ }
1290
+
1291
+ if (typeof quiz_version_id !== 'string') {
1292
+ return new Error('"quiz_version_id" is a required parameter of type string');
1293
+ }
1294
+
1295
+ if (typeof quiz_session_id !== 'string') {
1296
+ return new Error('"quiz_session_id" is a required parameter of type string');
1297
+ }
1298
+
1299
+ if (typeof url !== 'string') {
1300
+ return new Error('"url" is a required parameter of type string');
1301
+ }
1302
+
1303
+ bodyParams.quiz_id = quiz_id;
1304
+ bodyParams.quiz_version_id = quiz_version_id;
1305
+ bodyParams.quiz_session_id = quiz_session_id;
1306
+ bodyParams.url = url;
1307
+
1308
+ if (!helpers.isNil(section)) {
1309
+ if (typeof section !== 'string') {
1310
+ return new Error('"section" must be a string');
1311
+ }
1312
+
1313
+ queryParams.section = section;
1314
+ bodyParams.section = section;
1315
+ }
1316
+
1317
+ if (!helpers.isNil(result_count)) {
1318
+ if (typeof result_count !== 'number') {
1319
+ return new Error('"result_count" must be a number');
1320
+ }
1321
+
1322
+ bodyParams.result_count = result_count;
1323
+ }
1324
+
1325
+ if (!helpers.isNil(result_id)) {
1326
+ if (typeof result_id !== 'string') {
1327
+ return new Error('"result_id" must be a string');
1328
+ }
1329
+
1330
+ bodyParams.result_id = result_id;
1331
+ }
1332
+
1333
+ if (!helpers.isNil(result_page)) {
1334
+ if (typeof result_page !== 'number') {
1335
+ return new Error('"result_page" must be a number');
1336
+ }
1337
+
1338
+ bodyParams.result_page = result_page;
1339
+ }
1340
+
1341
+ bodyParams.action_class = 'result_load';
1342
+ var requestURL = "".concat(requestPath).concat(applyParamsAsString(queryParams, this.options));
1343
+ var requestMethod = 'POST';
1344
+ var requestBody = applyParams(bodyParams, _objectSpread(_objectSpread({}, this.options), {}, {
1345
+ requestMethod: requestMethod
1346
+ }));
1347
+ this.requests.queue(requestURL, requestMethod, requestBody, networkParameters);
1348
+ this.requests.send();
1349
+ return true;
1350
+ }
1351
+
1352
+ this.requests.send();
1353
+ return new Error('parameters are required of type object');
1354
+ }
1355
+ /**
1356
+ * Send quiz result click event to API
1357
+ *
1358
+ * @function trackQuizResultClick
1359
+ * @param {object} parameters - Additional parameters to be sent with request
1360
+ * @param {string} parameters.quiz_id - Quiz identifier
1361
+ * @param {string} parameters.quiz_version_id - Quiz version identifier
1362
+ * @param {string} parameters.quiz_session_id - Quiz session identifier associated with this conversion event
1363
+ * @param {string} [parameters.item_id] - Product item unique identifier (Either item_id or item_name is required)
1364
+ * @param {string} [parameters.item_name] - Product item name
1365
+ * @param {string} [parameters.section='Products'] - Index section
1366
+ * @param {number} [parameters.result_count] - Total number of results
1367
+ * @param {number} [parameters.result_page] - The page of the results
1368
+ * @param {string} [parameters.result_id] - Quiz result identifier (returned in response from Constructor)
1369
+ * @param {number} [parameters.result_position_on_page] - Position of clicked item
1370
+ * @param {number} [parameters.num_results_per_page] - Number of results shown
1371
+ * @param {object} [networkParameters] - Parameters relevant to the network request
1372
+ * @param {number} [networkParameters.timeout] - Request timeout (in milliseconds)
1373
+ * @returns {(true|Error)}
1374
+ * @description User viewed a quiz results page
1375
+ * @example
1376
+ * constructorio.tracker.trackQuizResultClick(
1377
+ * {
1378
+ * quiz_id: 'coffee-quiz',
1379
+ * quiz_version_id: '1231244',
1380
+ * quiz_session_id: '123',
1381
+ * item_id: '123',
1382
+ * item_name: 'espresso'
1383
+ * },
1384
+ * );
1385
+ */
1386
+ // eslint-disable-next-line complexity
1387
+
1388
+ }, {
1389
+ key: "trackQuizResultClick",
1390
+ value: function trackQuizResultClick(parameters) {
1391
+ var networkParameters = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
1392
+
1393
+ // Ensure parameters are provided (required)
1394
+ if (parameters && (0, _typeof2["default"])(parameters) === 'object' && !Array.isArray(parameters)) {
1395
+ var requestPath = "".concat(this.options.serviceUrl, "/v2/behavioral_action/quiz_result_click?");
1396
+ var quiz_id = parameters.quiz_id,
1397
+ quiz_version_id = parameters.quiz_version_id,
1398
+ quiz_session_id = parameters.quiz_session_id,
1399
+ item_id = parameters.item_id,
1400
+ item_name = parameters.item_name,
1401
+ result_count = parameters.result_count,
1402
+ result_id = parameters.result_id,
1403
+ result_page = parameters.result_page,
1404
+ num_results_per_page = parameters.num_results_per_page,
1405
+ result_position_on_page = parameters.result_position_on_page,
1406
+ _parameters$section3 = parameters.section,
1407
+ section = _parameters$section3 === void 0 ? 'Products' : _parameters$section3;
1408
+ var queryParams = {};
1409
+ var bodyParams = {}; // Ensure required parameters provided
1410
+
1411
+ if (typeof quiz_id !== 'string') {
1412
+ return new Error('"quiz_id" is a required parameter of type string');
1413
+ }
1414
+
1415
+ if (typeof quiz_version_id !== 'string') {
1416
+ return new Error('"quiz_version_id" is a required parameter of type string');
1417
+ }
1418
+
1419
+ if (typeof quiz_session_id !== 'string') {
1420
+ return new Error('"quiz_session_id" is a required parameter of type string');
1421
+ }
1422
+
1423
+ if (typeof item_id !== 'string' && typeof item_name !== 'string') {
1424
+ return new Error('"item_id" or "item_name" is a required parameter of type string');
1425
+ }
1426
+
1427
+ bodyParams.quiz_id = quiz_id;
1428
+ bodyParams.quiz_version_id = quiz_version_id;
1429
+ bodyParams.quiz_session_id = quiz_session_id;
1430
+
1431
+ if (!helpers.isNil(item_id)) {
1432
+ if (typeof item_id !== 'string') {
1433
+ return new Error('"item_id" must be a string');
1434
+ }
1435
+
1436
+ bodyParams.item_id = item_id;
1437
+ }
1438
+
1439
+ if (!helpers.isNil(item_name)) {
1440
+ if (typeof item_name !== 'string') {
1441
+ return new Error('"item_name" must be a string');
1442
+ }
1443
+
1444
+ bodyParams.item_name = item_name;
1445
+ }
1446
+
1447
+ if (!helpers.isNil(section)) {
1448
+ if (typeof section !== 'string') {
1449
+ return new Error('"section" must be a string');
1450
+ }
1451
+
1452
+ queryParams.section = section;
1453
+ }
1454
+
1455
+ if (!helpers.isNil(result_count)) {
1456
+ if (typeof result_count !== 'number') {
1457
+ return new Error('"result_count" must be a number');
1458
+ }
1459
+
1460
+ bodyParams.result_count = result_count;
1461
+ }
1462
+
1463
+ if (!helpers.isNil(result_id)) {
1464
+ if (typeof result_id !== 'string') {
1465
+ return new Error('"result_id" must be a string');
1466
+ }
1467
+
1468
+ bodyParams.result_id = result_id;
1469
+ }
1470
+
1471
+ if (!helpers.isNil(result_page)) {
1472
+ if (typeof result_page !== 'number') {
1473
+ return new Error('"result_page" must be a number');
1474
+ }
1475
+
1476
+ bodyParams.result_page = result_page;
1477
+ }
1478
+
1479
+ if (!helpers.isNil(num_results_per_page)) {
1480
+ if (typeof num_results_per_page !== 'number') {
1481
+ return new Error('"num_results_per_page" must be a number');
1482
+ }
1483
+
1484
+ bodyParams.num_results_per_page = num_results_per_page;
1485
+ }
1486
+
1487
+ if (!helpers.isNil(result_position_on_page)) {
1488
+ if (typeof result_position_on_page !== 'number') {
1489
+ return new Error('"result_position_on_page" must be a number');
1490
+ }
1491
+
1492
+ bodyParams.result_position_on_page = result_position_on_page;
1493
+ }
1494
+
1495
+ bodyParams.action_class = 'result_click';
1496
+ var requestURL = "".concat(requestPath).concat(applyParamsAsString(queryParams, this.options));
1497
+ var requestMethod = 'POST';
1498
+ var requestBody = applyParams(bodyParams, _objectSpread(_objectSpread({}, this.options), {}, {
1499
+ requestMethod: requestMethod
1500
+ }));
1501
+ this.requests.queue(requestURL, requestMethod, requestBody, networkParameters);
1502
+ this.requests.send();
1503
+ return true;
1504
+ }
1505
+
1506
+ this.requests.send();
1507
+ return new Error('parameters are required of type object');
1508
+ }
1509
+ /**
1510
+ * Send quiz conversion event to API
1511
+ *
1512
+ * @function trackQuizConversion
1513
+ * @param {object} parameters - Additional parameters to be sent with request
1514
+ * @param {string} parameters.quiz_id - Quiz identifier
1515
+ * @param {string} parameters.quiz_version_id - Quiz version identifier
1516
+ * @param {string} parameters.quiz_session_id - Quiz session identifier associated with this conversion event
1517
+ * @param {string} [parameters.item_id] - Product item unique identifier (Either item_id or item_name is required)
1518
+ * @param {string} [parameters.item_name] - Product item name
1519
+ * @param {string} [parameters.variation_id] - Product item variation unique identifier
1520
+ * @param {string} [parameters.revenue] - Sale price if available, otherwise the regular (retail) price of item
1521
+ * @param {string} [parameters.section='Products'] - Index section
1522
+ * @param {string} [parameters.type='add_to_cart'] - Conversion type
1523
+ * @param {boolean} [parameters.is_custom_type] - Specify if type is custom conversion type
1524
+ * @param {string} [parameters.display_name] - Display name for the custom conversion type
1525
+ * @param {object} [networkParameters] - Parameters relevant to the network request
1526
+ * @param {number} [networkParameters.timeout] - Request timeout (in milliseconds)
1527
+ * @returns {(true|Error)}
1528
+ * @description User viewed a quiz results page
1529
+ * @example
1530
+ * constructorio.tracker.trackQuizConversion(
1531
+ * {
1532
+ * quiz_id: 'coffee-quiz',
1533
+ * quiz_version_id: '1231244',
1534
+ * quiz_session_id: '3123',
1535
+ * item_name: 'espresso',
1536
+ * variation_id: '167',
1537
+ * type: 'add_to_cart",
1538
+ * revenue: '1.0"
1539
+ * },
1540
+ * );
1541
+ */
1542
+ // eslint-disable-next-line complexity
1543
+
1544
+ }, {
1545
+ key: "trackQuizConversion",
1546
+ value: function trackQuizConversion(parameters) {
1547
+ var networkParameters = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
1548
+
1549
+ // Ensure parameters are provided (required)
1550
+ if (parameters && (0, _typeof2["default"])(parameters) === 'object' && !Array.isArray(parameters)) {
1551
+ var requestPath = "".concat(this.options.serviceUrl, "/v2/behavioral_action/quiz_conversion?");
1552
+ var quiz_id = parameters.quiz_id,
1553
+ quiz_version_id = parameters.quiz_version_id,
1554
+ quiz_session_id = parameters.quiz_session_id,
1555
+ item_id = parameters.item_id,
1556
+ item_name = parameters.item_name,
1557
+ variation_id = parameters.variation_id,
1558
+ revenue = parameters.revenue,
1559
+ _parameters$section4 = parameters.section,
1560
+ section = _parameters$section4 === void 0 ? 'Products' : _parameters$section4,
1561
+ type = parameters.type,
1562
+ is_custom_type = parameters.is_custom_type,
1563
+ display_name = parameters.display_name;
1564
+ var queryParams = {};
1565
+ var bodyParams = {}; // Ensure required parameters provided
1566
+
1567
+ if (typeof quiz_id !== 'string') {
1568
+ return new Error('"quiz_id" is a required parameter of type string');
1569
+ }
1570
+
1571
+ if (typeof quiz_version_id !== 'string') {
1572
+ return new Error('"quiz_version_id" is a required parameter of type string');
1573
+ }
1574
+
1575
+ if (typeof quiz_session_id !== 'string') {
1576
+ return new Error('"quiz_session_id" is a required parameter of type string');
1577
+ }
1578
+
1579
+ if (typeof item_id !== 'string' && typeof item_name !== 'string') {
1580
+ return new Error('"item_id" or "item_name" is a required parameter of type string');
1581
+ }
1582
+
1583
+ bodyParams.quiz_id = quiz_id;
1584
+ bodyParams.quiz_version_id = quiz_version_id;
1585
+ bodyParams.quiz_session_id = quiz_session_id;
1586
+
1587
+ if (!helpers.isNil(item_id)) {
1588
+ if (typeof item_id !== 'string') {
1589
+ return new Error('"item_id" must be a string');
1590
+ }
1591
+
1592
+ bodyParams.item_id = item_id;
1593
+ }
1594
+
1595
+ if (!helpers.isNil(item_name)) {
1596
+ if (typeof item_name !== 'string') {
1597
+ return new Error('"item_name" must be a string');
1598
+ }
1599
+
1600
+ bodyParams.item_name = item_name;
1601
+ }
1602
+
1603
+ if (!helpers.isNil(variation_id)) {
1604
+ if (typeof variation_id !== 'string') {
1605
+ return new Error('"variation_id" must be a string');
1606
+ }
1607
+
1608
+ bodyParams.variation_id = variation_id;
1609
+ }
1610
+
1611
+ if (!helpers.isNil(revenue)) {
1612
+ if (typeof revenue !== 'string') {
1613
+ return new Error('"revenue" must be a string');
1614
+ }
1615
+
1616
+ bodyParams.revenue = revenue;
1617
+ }
1618
+
1619
+ if (!helpers.isNil(section)) {
1620
+ if (typeof section !== 'string') {
1621
+ return new Error('"section" must be a string');
1622
+ }
1623
+
1624
+ bodyParams.section = section;
1625
+ }
1626
+
1627
+ if (!helpers.isNil(type)) {
1628
+ if (typeof type !== 'string') {
1629
+ return new Error('"type" must be a string');
1630
+ }
1631
+
1632
+ bodyParams.type = type;
1633
+ }
1634
+
1635
+ if (!helpers.isNil(is_custom_type)) {
1636
+ if (typeof is_custom_type !== 'boolean') {
1637
+ return new Error('"is_custom_type" must be a boolean');
1638
+ }
1639
+
1640
+ bodyParams.is_custom_type = is_custom_type;
1641
+ }
1642
+
1643
+ if (!helpers.isNil(display_name)) {
1644
+ if (typeof display_name !== 'string') {
1645
+ return new Error('"display_name" must be a string');
1646
+ }
1647
+
1648
+ bodyParams.display_name = display_name;
1649
+ }
1650
+
1651
+ bodyParams.action_class = 'conversion';
1652
+ var requestURL = "".concat(requestPath).concat(applyParamsAsString(queryParams, this.options));
1653
+ var requestMethod = 'POST';
1654
+ var requestBody = applyParams(bodyParams, _objectSpread(_objectSpread({}, this.options), {}, {
1655
+ requestMethod: requestMethod
1656
+ }));
1657
+ this.requests.queue(requestURL, requestMethod, requestBody, networkParameters);
1658
+ this.requests.send();
1659
+ return true;
1660
+ }
1661
+
1662
+ this.requests.send();
1663
+ return new Error('parameters are required of type object');
1664
+ }
1238
1665
  /**
1239
1666
  * Subscribe to success or error messages emitted by tracking requests
1240
1667
  *
@@ -171,5 +171,51 @@ declare class Tracker {
171
171
  networkParameters?: NetworkParameters
172
172
  ): true | Error;
173
173
 
174
+ trackQuizResultsLoaded(
175
+ parameters: {
176
+ quiz_id: string;
177
+ quiz_version_id: string;
178
+ url: string;
179
+ section?: string;
180
+ result_count?: number;
181
+ result_page?: number;
182
+ result_id?: string;
183
+ },
184
+ networkParameters?: NetworkParameters
185
+ ): true | Error;
186
+
187
+ trackQuizResultClick(
188
+ parameters: {
189
+ quiz_id: string;
190
+ quiz_version_id: string;
191
+ item_id?: string;
192
+ item_name?: string;
193
+ section?: string;
194
+ result_count?: number;
195
+ result_page?: number;
196
+ result_id?: string;
197
+ result_position_on_page?: number;
198
+ num_results_per_page?: number;
199
+ },
200
+ networkParameters?: NetworkParameters
201
+ ): true | Error;
202
+
203
+ trackQuizConversion(
204
+ parameters: {
205
+ quiz_id: string;
206
+ quiz_version_id: string;
207
+ quiz_session_id: string;
208
+ item_id?: string;
209
+ item_name?: string;
210
+ section?: string;
211
+ variation_id?: string;
212
+ revenue?: string;
213
+ type?: string;
214
+ is_custom_type?: boolean;
215
+ display_name?: string;
216
+ },
217
+ networkParameters?: NetworkParameters
218
+ ): true | Error;
219
+
174
220
  on(messageType: string, callback: Function): true | Error;
175
221
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@constructor-io/constructorio-client-javascript",
3
- "version": "2.34.7",
3
+ "version": "2.34.8",
4
4
  "description": "Constructor.io JavaScript client",
5
5
  "main": "lib/constructorio.js",
6
6
  "types": "lib/types/constructorio.d.ts",