@constructor-io/constructorio-client-javascript 2.71.3 → 2.72.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/.DS_Store ADDED
Binary file
@@ -1773,12 +1773,11 @@ var Tracker = /*#__PURE__*/function () {
1773
1773
 
1774
1774
  /**
1775
1775
  * Send browse redirect event to API
1776
- * @private
1777
1776
  * @function trackBrowseRedirect
1778
1777
  * @param {object} parameters - Additional parameters to be sent with request
1779
1778
  * @param {string} parameters.searchTerm - The search query that caused redirect
1780
- * @param {string} parameters.filterName - Filter name
1781
- * @param {string} parameters.filterValue - Filter value
1779
+ * @param {string} parameters.filterName - Filter name of the browse page the user is redirected to. Should be the same value sent in `trackBrowseResultsLoaded`
1780
+ * @param {string} parameters.filterValue - Filter value of the browse page the user is redirected to. Should be the same value sent in `trackBrowseResultsLoaded`
1782
1781
  * @param {string} [parameters.userInput] - The text that a user had typed at the moment when submitting search request
1783
1782
  * @param {string} [parameters.redirectToUrl] - URL of the page to which user is redirected
1784
1783
  * @param {string} [parameters.section="Products"] - Index section
@@ -19,6 +19,7 @@ var PII_REGEX = [{
19
19
  }
20
20
  // Add more PII REGEX
21
21
  ];
22
+ var URL_MAX_LEN = 2000;
22
23
  var utils = {
23
24
  trimNonBreakingSpaces: function trimNonBreakingSpaces(string) {
24
25
  return string.replace(/\s/g, ' ').trim();
@@ -43,6 +44,53 @@ var utils = {
43
44
  });
44
45
  return cleanedParams;
45
46
  },
47
+ trimUrl: function trimUrl(urlObj) {
48
+ var maxLen = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : URL_MAX_LEN;
49
+ var urlString = urlObj.toString();
50
+ if (urlString.length <= maxLen) {
51
+ return urlString;
52
+ }
53
+ var urlCopy = new URL(urlObj.toString());
54
+ var searchParams = urlCopy.searchParams;
55
+ var paramEntries = Array.from(searchParams.entries());
56
+ if (paramEntries.length === 0) {
57
+ return utils.truncateString(urlString, maxLen);
58
+ }
59
+ paramEntries.sort(function (a, b) {
60
+ var aLength = a[0].length + a[1].length;
61
+ var bLength = b[0].length + b[1].length;
62
+ return bLength - aLength;
63
+ });
64
+ for (var i = 0; i < paramEntries.length; i += 1) {
65
+ if (urlString.length <= maxLen) {
66
+ break;
67
+ }
68
+ searchParams["delete"](paramEntries[i][0]);
69
+ urlString = urlCopy.toString();
70
+ }
71
+ if (urlString.length > maxLen) {
72
+ return utils.truncateString(urlString, maxLen);
73
+ }
74
+ return urlString;
75
+ },
76
+ cleanAndValidateUrl: function cleanAndValidateUrl(url) {
77
+ var baseUrl = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : undefined;
78
+ var validatedUrl = null;
79
+ try {
80
+ var _url;
81
+ // Handle android app referrers
82
+ if ((_url = url) !== null && _url !== void 0 && _url.startsWith('android-app')) {
83
+ var _url2;
84
+ url = (_url2 = url) === null || _url2 === void 0 ? void 0 : _url2.replace('android-app', 'https');
85
+ }
86
+ var urlObj = new URL(url, baseUrl);
87
+ var trimmedUrl = new URL(utils.trimUrl(urlObj));
88
+ validatedUrl = trimmedUrl.toString();
89
+ } catch (e) {
90
+ // do nothing
91
+ }
92
+ return validatedUrl;
93
+ },
46
94
  throwHttpErrorFromResponse: function throwHttpErrorFromResponse(error, response) {
47
95
  return response.json().then(function (json) {
48
96
  error.message = json.message;
@@ -85,22 +133,25 @@ var utils = {
85
133
  return {};
86
134
  },
87
135
  getDocumentReferrer: function getDocumentReferrer() {
88
- if (utils.canUseDOM()) {
89
- var _document;
90
- return (_document = document) === null || _document === void 0 ? void 0 : _document.referrer;
136
+ var documentReferrer = null;
137
+ try {
138
+ if (utils.canUseDOM()) {
139
+ documentReferrer = utils.cleanAndValidateUrl(document.referrer);
140
+ }
141
+ } catch (e) {
142
+ // do nothing
91
143
  }
92
- return null;
144
+ return documentReferrer;
93
145
  },
94
146
  getCanonicalUrl: function getCanonicalUrl() {
95
147
  var canonicalURL = null;
96
148
  try {
97
149
  if (utils.canUseDOM()) {
98
- var _document2;
99
- var linkEle = (_document2 = document) === null || _document2 === void 0 ? void 0 : _document2.querySelector('link[rel="canonical"]');
150
+ var _document;
151
+ var linkEle = (_document = document) === null || _document === void 0 ? void 0 : _document.querySelector('link[rel="canonical"]');
100
152
  var href = linkEle === null || linkEle === void 0 ? void 0 : linkEle.getAttribute('href');
101
153
  if (href) {
102
- var url = new URL(href, document.location.href);
103
- canonicalURL = url.toString();
154
+ canonicalURL = utils.cleanAndValidateUrl(href, document.location.href);
104
155
  }
105
156
  }
106
157
  } catch (e) {
package/lib/version.js CHANGED
@@ -4,4 +4,4 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports["default"] = void 0;
7
- var _default = exports["default"] = '2.71.3';
7
+ var _default = exports["default"] = '2.72.1';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@constructor-io/constructorio-client-javascript",
3
- "version": "2.71.3",
3
+ "version": "2.72.1",
4
4
  "description": "Constructor.io JavaScript client",
5
5
  "main": "lib/constructorio.js",
6
6
  "types": "lib/types/index.d.ts",