rudder-sdk-js 2.9.1 → 2.9.4

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 -32
  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.1';
4942
+ var CONFIG_URL = 'https://api.rudderlabs.com/sourceConfig/?p=npm&v=2.9.4';
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.1";
10600
+ this.version = "2.9.4";
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.1";
10609
+ this.version = "2.9.4";
10602
10610
  }); // Operating System information class
10603
10611
 
10604
10612
 
@@ -10642,13 +10650,18 @@
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;
10654
+ this.userAgent = navigator.userAgent; // For supporting Brave browser detection,
10655
+ // add "Brave/<version>" to the user agent with the version value from the Chrome component
10646
10656
 
10647
10657
  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;
10658
+ // Example:
10659
+ // 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
10660
+ var matchedArr = this.userAgent.match(/(Chrome)\/([\w\.]+)/i);
10661
+
10662
+ if (matchedArr) {
10663
+ this.userAgent = "".concat(this.userAgent, " Brave/").concat(matchedArr[2]);
10664
+ }
10652
10665
  } // property name differs based on browser version
10653
10666
 
10654
10667
 
@@ -13260,7 +13273,7 @@
13260
13273
  if (API_KEY.match(apiKeyRegex) !== null) return;
13261
13274
  window.rsBugsnagClient = window.Bugsnag.start({
13262
13275
  apiKey: API_KEY,
13263
- appVersion: "2.9.1",
13276
+ appVersion: "2.9.4",
13264
13277
  // Set SDK version as the app version
13265
13278
  metadata: META_DATA,
13266
13279
  onError: function onError(event) {
@@ -13425,6 +13438,24 @@
13425
13438
  return callback();
13426
13439
  });
13427
13440
  }
13441
+ /**
13442
+ * A function to validate integration SDK is available in window
13443
+ * and integration constructor is not undefined
13444
+ * @param {string} pluginName
13445
+ * @param {string} modName
13446
+ * @returns boolean
13447
+ */
13448
+
13449
+ }, {
13450
+ key: "integrationSDKLoaded",
13451
+ value: function integrationSDKLoaded(pluginName, modName) {
13452
+ try {
13453
+ return window.hasOwnProperty(pluginName) && window[pluginName][modName] && typeof window[pluginName][modName].prototype.constructor !== 'undefined';
13454
+ } catch (e) {
13455
+ handleError(e);
13456
+ return false;
13457
+ }
13458
+ }
13428
13459
  /**
13429
13460
  * Process the response from control plane and
13430
13461
  * call initialize for integrations
@@ -13496,11 +13527,10 @@
13496
13527
  var suffix = ''; // default suffix
13497
13528
  // Get the CDN base URL is rudder staging url
13498
13529
 
13499
- var _checkSDKUrl = checkSDKUrl(),
13500
- rudderSDK = _checkSDKUrl.rudderSDK,
13501
- staging = _checkSDKUrl.staging;
13530
+ var _getSDKUrlInfo = getSDKUrlInfo(),
13531
+ isStaging = _getSDKUrlInfo.isStaging;
13502
13532
 
13503
- if (rudderSDK && staging) {
13533
+ if (isStaging) {
13504
13534
  suffix = '-staging'; // stagging suffix
13505
13535
  }
13506
13536
 
@@ -13520,7 +13550,7 @@
13520
13550
 
13521
13551
  var self = _this2;
13522
13552
  var interval = setInterval(function () {
13523
- if (window.hasOwnProperty(pluginName)) {
13553
+ if (self.integrationSDKLoaded(pluginName, modName)) {
13524
13554
  var intMod = window[pluginName];
13525
13555
  clearInterval(interval); // logger.debug(pluginName, " dynamically loaded integration SDK");
13526
13556
 
@@ -13923,7 +13953,7 @@
13923
13953
  checkReservedKeywords(rudderElement.message, type); // if not specified at event level, All: true is default
13924
13954
 
13925
13955
  var clientSuppliedIntegrations = rudderElement.message.integrations || {
13926
- 'All': true
13956
+ All: true
13927
13957
  }; // structure user supplied integrations object to rudder format
13928
13958
 
13929
13959
  transformToRudderNames(clientSuppliedIntegrations);
@@ -14263,11 +14293,11 @@
14263
14293
  }
14264
14294
  } else {
14265
14295
  // Get the CDN base URL from the included 'rudder-analytics.min.js' script tag
14266
- var _checkSDKUrl2 = checkSDKUrl(),
14267
- rudderSDK = _checkSDKUrl2.rudderSDK;
14296
+ var _getSDKUrlInfo2 = getSDKUrlInfo(),
14297
+ sdkURL = _getSDKUrlInfo2.sdkURL;
14268
14298
 
14269
- if (rudderSDK) {
14270
- this.destSDKBaseURL = rudderSDK.split('/').slice(0, -1).concat(CDN_INT_DIR).join('/');
14299
+ if (sdkURL) {
14300
+ this.destSDKBaseURL = sdkURL.split('/').slice(0, -1).concat(CDN_INT_DIR).join('/');
14271
14301
  }
14272
14302
  }
14273
14303
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rudder-sdk-js",
3
- "version": "2.9.1",
3
+ "version": "2.9.4",
4
4
  "description": "RudderStack Javascript SDK",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",