rudder-sdk-js 2.9.0 → 2.9.3

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 (2) hide show
  1. package/index.js +62 -33
  2. package/package.json +1 -1
package/index.js CHANGED
@@ -4939,7 +4939,7 @@
4939
4939
 
4940
4940
  // Reserved Keywords for properties/traits
4941
4941
  var RESERVED_KEYS = ['anonymous_id', 'id', 'sent_at', 'received_at', 'timestamp', 'original_timestamp', 'event_text', 'event'];
4942
- var CONFIG_URL = 'https://api.rudderlabs.com/sourceConfig/?p=npm&v=2.9.0';
4942
+ var CONFIG_URL = 'https://api.rudderlabs.com/sourceConfig/?p=npm&v=2.9.3';
4943
4943
  var CDN_INT_DIR = 'js-integrations';
4944
4944
  var DEST_SDK_BASE_URL = "https://cdn.rudderlabs.com/v1.1/".concat(CDN_INT_DIR);
4945
4945
  var MAX_WAIT_FOR_INTEGRATION_LOAD = 10000;
@@ -10371,7 +10371,15 @@
10371
10371
  }
10372
10372
 
10373
10373
  function getReferrer() {
10374
- return document.referrer || "$direct";
10374
+ // This error handling is in place to avoid accessing dead object(document)
10375
+ var defaultReferrer = "$direct";
10376
+
10377
+ try {
10378
+ return document.referrer || defaultReferrer;
10379
+ } catch (e) {
10380
+ logger.error("Error trying to access 'document.referrer': ", e);
10381
+ return defaultReferrer;
10382
+ }
10375
10383
  }
10376
10384
 
10377
10385
  function getReferringDomain(referrer) {
@@ -10557,28 +10565,28 @@
10557
10565
  return CONFIG_URL.concat(CONFIG_URL.includes("?") ? "&" : "?").concat(writeKey ? "writeKey=".concat(writeKey) : "");
10558
10566
  };
10559
10567
 
10560
- var checkSDKUrl = function checkSDKUrl() {
10568
+ var getSDKUrlInfo = function getSDKUrlInfo() {
10561
10569
  var scripts = document.getElementsByTagName("script");
10562
- var rudderSDK = undefined;
10563
- var staging = false;
10570
+ var sdkURL;
10571
+ var isStaging = false;
10564
10572
 
10565
10573
  for (var i = 0; i < scripts.length; i += 1) {
10566
- var curScriptSrc = removeTrailingSlashes(scripts[i].getAttribute("src")); // only in case of staging SDK staging env will be set to true
10574
+ var curScriptSrc = removeTrailingSlashes(scripts[i].getAttribute("src"));
10567
10575
 
10568
- if (curScriptSrc && curScriptSrc.startsWith("http") && (curScriptSrc.endsWith("rudder-analytics.min.js") || curScriptSrc.endsWith("rudder-analytics-staging.min.js"))) {
10569
- rudderSDK = curScriptSrc;
10576
+ if (curScriptSrc) {
10577
+ var urlMatches = curScriptSrc.match(/^(https?:)?\/\/.*rudder-analytics(-staging)?(\.min)?\.js$/);
10570
10578
 
10571
- if (curScriptSrc.endsWith("rudder-analytics-staging.min.js")) {
10572
- staging = true;
10579
+ if (urlMatches) {
10580
+ sdkURL = curScriptSrc;
10581
+ isStaging = urlMatches[2] !== undefined;
10582
+ break;
10573
10583
  }
10574
-
10575
- break;
10576
10584
  }
10577
10585
  }
10578
10586
 
10579
10587
  return {
10580
- rudderSDK: rudderSDK,
10581
- staging: staging
10588
+ sdkURL: sdkURL,
10589
+ isStaging: isStaging
10582
10590
  };
10583
10591
  };
10584
10592
 
@@ -10589,7 +10597,7 @@
10589
10597
  this.build = "1.0.0";
10590
10598
  this.name = "RudderLabs JavaScript SDK";
10591
10599
  this.namespace = "com.rudderlabs.javascript";
10592
- this.version = "2.9.0";
10600
+ this.version = "2.9.3";
10593
10601
  });
10594
10602
 
10595
10603
  /* eslint-disable max-classes-per-file */
@@ -10598,7 +10606,7 @@
10598
10606
  _classCallCheck(this, RudderLibraryInfo);
10599
10607
 
10600
10608
  this.name = "RudderLabs JavaScript SDK";
10601
- this.version = "2.9.0";
10609
+ this.version = "2.9.3";
10602
10610
  }); // Operating System information class
10603
10611
 
10604
10612
 
@@ -10642,13 +10650,17 @@
10642
10650
  this.screen.height = window.screen.height;
10643
10651
  this.screen.density = window.devicePixelRatio;
10644
10652
  this.screen.innerWidth = window.innerWidth;
10645
- this.screen.innerHeight = window.innerHeight; // detect brave browser and append to the user agent
10653
+ this.screen.innerHeight = window.innerHeight; // For supporting Brave browser detection,
10654
+ // add "Brave/<version>" to the user agent with the version value from the Chrome component
10646
10655
 
10647
10656
  if (navigator.brave && Object.getPrototypeOf(navigator.brave).isBrave) {
10648
- var version = navigator.userAgent.match(/(Chrome)\/([\w\.]+)/i)[2];
10649
- this.userAgent = "".concat(navigator.userAgent, " Brave/").concat(version);
10650
- } else {
10651
- this.userAgent = navigator.userAgent;
10657
+ // Example:
10658
+ // Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.5060.114 Safari/537.36
10659
+ var matchedArr = this.userAgent.match(/(Chrome)\/([\w\.]+)/i);
10660
+
10661
+ if (matchedArr) {
10662
+ this.userAgent = "".concat(this.userAgent, " Brave/").concat(matchedArr[2]);
10663
+ }
10652
10664
  } // property name differs based on browser version
10653
10665
 
10654
10666
 
@@ -13090,7 +13102,7 @@
13090
13102
  ADROLL: "Adroll",
13091
13103
  DCM_FLOODLIGHT: "DCMFloodlight",
13092
13104
  MATOMO: "Matomo",
13093
- VERO: "VERO"
13105
+ VERO: "Vero"
13094
13106
  };
13095
13107
 
13096
13108
  /* eslint-disable class-methods-use-this */
@@ -13260,7 +13272,7 @@
13260
13272
  if (API_KEY.match(apiKeyRegex) !== null) return;
13261
13273
  window.rsBugsnagClient = window.Bugsnag.start({
13262
13274
  apiKey: API_KEY,
13263
- appVersion: "2.9.0",
13275
+ appVersion: "2.9.3",
13264
13276
  // Set SDK version as the app version
13265
13277
  metadata: META_DATA,
13266
13278
  onError: function onError(event) {
@@ -13425,6 +13437,24 @@
13425
13437
  return callback();
13426
13438
  });
13427
13439
  }
13440
+ /**
13441
+ * A function to validate integration SDK is available in window
13442
+ * and integration constructor is not undefined
13443
+ * @param {string} pluginName
13444
+ * @param {string} modName
13445
+ * @returns boolean
13446
+ */
13447
+
13448
+ }, {
13449
+ key: "integrationSDKLoaded",
13450
+ value: function integrationSDKLoaded(pluginName, modName) {
13451
+ try {
13452
+ return window.hasOwnProperty(pluginName) && window[pluginName][modName] && typeof window[pluginName][modName].prototype.constructor !== 'undefined';
13453
+ } catch (e) {
13454
+ handleError(e);
13455
+ return false;
13456
+ }
13457
+ }
13428
13458
  /**
13429
13459
  * Process the response from control plane and
13430
13460
  * call initialize for integrations
@@ -13496,11 +13526,10 @@
13496
13526
  var suffix = ''; // default suffix
13497
13527
  // Get the CDN base URL is rudder staging url
13498
13528
 
13499
- var _checkSDKUrl = checkSDKUrl(),
13500
- rudderSDK = _checkSDKUrl.rudderSDK,
13501
- staging = _checkSDKUrl.staging;
13529
+ var _getSDKUrlInfo = getSDKUrlInfo(),
13530
+ isStaging = _getSDKUrlInfo.isStaging;
13502
13531
 
13503
- if (rudderSDK && staging) {
13532
+ if (isStaging) {
13504
13533
  suffix = '-staging'; // stagging suffix
13505
13534
  }
13506
13535
 
@@ -13520,7 +13549,7 @@
13520
13549
 
13521
13550
  var self = _this2;
13522
13551
  var interval = setInterval(function () {
13523
- if (window.hasOwnProperty(pluginName)) {
13552
+ if (self.integrationSDKLoaded(pluginName, modName)) {
13524
13553
  var intMod = window[pluginName];
13525
13554
  clearInterval(interval); // logger.debug(pluginName, " dynamically loaded integration SDK");
13526
13555
 
@@ -13923,7 +13952,7 @@
13923
13952
  checkReservedKeywords(rudderElement.message, type); // if not specified at event level, All: true is default
13924
13953
 
13925
13954
  var clientSuppliedIntegrations = rudderElement.message.integrations || {
13926
- 'All': true
13955
+ All: true
13927
13956
  }; // structure user supplied integrations object to rudder format
13928
13957
 
13929
13958
  transformToRudderNames(clientSuppliedIntegrations);
@@ -14263,11 +14292,11 @@
14263
14292
  }
14264
14293
  } else {
14265
14294
  // Get the CDN base URL from the included 'rudder-analytics.min.js' script tag
14266
- var _checkSDKUrl2 = checkSDKUrl(),
14267
- rudderSDK = _checkSDKUrl2.rudderSDK;
14295
+ var _getSDKUrlInfo2 = getSDKUrlInfo(),
14296
+ sdkURL = _getSDKUrlInfo2.sdkURL;
14268
14297
 
14269
- if (rudderSDK) {
14270
- this.destSDKBaseURL = rudderSDK.split('/').slice(0, -1).concat(CDN_INT_DIR).join('/');
14298
+ if (sdkURL) {
14299
+ this.destSDKBaseURL = sdkURL.split('/').slice(0, -1).concat(CDN_INT_DIR).join('/');
14271
14300
  }
14272
14301
  }
14273
14302
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rudder-sdk-js",
3
- "version": "2.9.0",
3
+ "version": "2.9.3",
4
4
  "description": "RudderStack Javascript SDK",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",