rudder-sdk-js 1.2.16 → 1.3.2

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 (3) hide show
  1. package/index.d.ts +23 -0
  2. package/index.js +241 -33
  3. package/package.json +1 -1
package/index.d.ts CHANGED
@@ -29,6 +29,26 @@ declare module "rudder-sdk-js" {
29
29
  maxItems?: number;
30
30
  }
31
31
 
32
+ /**
33
+ * Represents the beacon queue options parameter in loadOptions type
34
+ */
35
+ interface beaconQueueOptions {
36
+ // Maximum number of events in storage
37
+ maxItems?: number;
38
+ // Time in milliseconds to flush the queue autometically
39
+ flushQueueInterval?: number;
40
+ }
41
+
42
+ /**
43
+ * Represents the beacon queue options parameter in loadOptions type
44
+ */
45
+ interface cookieConsentManager {
46
+ // OneTrust
47
+ oneTrust?: {
48
+ enabled: boolean;
49
+ };
50
+ }
51
+
32
52
  /**
33
53
  * Represents the options parameter in the load API
34
54
  */
@@ -51,6 +71,9 @@ declare module "rudder-sdk-js" {
51
71
  sendAdblockPage?: boolean;
52
72
  sendAdblockPageOptions?: apiOptions;
53
73
  clientSuppliedCallbacks?: { string: () => void };
74
+ useBeacon?: boolean; // Defaults to false
75
+ beaconQueueOptions?: beaconQueueOptions;
76
+ cookieConsentManager?: cookieConsentManager;
54
77
  }
55
78
 
56
79
  /**
package/index.js CHANGED
@@ -5464,7 +5464,12 @@
5464
5464
  "Post Affiliate Pro": "POST_AFFILIATE_PRO",
5465
5465
  postaffiliatepro: "POST_AFFILIATE_PRO",
5466
5466
  POSTAFFILIATEPRO: "POST_AFFILIATE_PRO",
5467
- POST_AFFILIATE_PRO: "POST_AFFILIATE_PRO"
5467
+ POST_AFFILIATE_PRO: "POST_AFFILIATE_PRO",
5468
+ LaunchDarkly: "LAUNCHDARKLY",
5469
+ Launch_Darkly: "LAUNCHDARKLY",
5470
+ LAUNCHDARKLY: "LAUNCHDARKLY",
5471
+ "Launch Darkly": "LAUNCHDARKLY",
5472
+ launchDarkly: "LAUNCHDARKLY"
5468
5473
  };
5469
5474
 
5470
5475
  // from client native integration name to server identified display name
@@ -5511,7 +5516,8 @@
5511
5516
  QUALTRICS: "Qualtrics",
5512
5517
  SENTRY: "Sentry",
5513
5518
  GOOGLE_OPTIMIZE: "GoogleOptimize",
5514
- POST_AFFILIATE_PRO: "PostAffiliatePro"
5519
+ POST_AFFILIATE_PRO: "PostAffiliatePro",
5520
+ LAUNCHDARKLY: "LaunchDarkly"
5515
5521
  };
5516
5522
 
5517
5523
  // Reserved Keywords for properties/triats
@@ -5555,7 +5561,7 @@
5555
5561
  PRODUCT_REVIEWED: "Product Reviewed"
5556
5562
  }; // Enumeration for integrations supported
5557
5563
 
5558
- var CONFIG_URL = "https://api.rudderlabs.com/sourceConfig/?p=npm&v=1.2.16";
5564
+ var CONFIG_URL = "https://api.rudderlabs.com/sourceConfig/?p=npm&v=1.3.2";
5559
5565
  var MAX_WAIT_FOR_INTEGRATION_LOAD = 10000;
5560
5566
  var INTEGRATION_LOAD_CHECK_INTERVAL = 1000;
5561
5567
  /* module.exports = {
@@ -22872,10 +22878,17 @@
22872
22878
  js.async = async === undefined ? defaultAsyncState : async;
22873
22879
  js.type = "text/javascript";
22874
22880
  js.id = id;
22875
- var e = document.getElementsByTagName("script")[0];
22876
- logger.debug("==parent script==", e);
22877
- logger.debug("==adding script==", js);
22878
- e.parentNode.insertBefore(js, e);
22881
+ var headElmColl = document.getElementsByTagName("head");
22882
+
22883
+ if (headElmColl.length !== 0) {
22884
+ logger.debug("==adding script==", js);
22885
+ headElmColl[0].insertBefore(js, headElmColl[0].firstChild);
22886
+ } else {
22887
+ var e = document.getElementsByTagName("script")[0];
22888
+ logger.debug("==parent script==", e);
22889
+ logger.debug("==adding script==", js);
22890
+ e.parentNode.insertBefore(js, e);
22891
+ }
22879
22892
  };
22880
22893
 
22881
22894
  var AdobeAnalytics = /*#__PURE__*/function () {
@@ -27541,12 +27554,13 @@
27541
27554
  camelcase.default = default_1;
27542
27555
 
27543
27556
  var Fullstory = /*#__PURE__*/function () {
27544
- function Fullstory(config) {
27557
+ function Fullstory(config, analytics) {
27545
27558
  _classCallCheck(this, Fullstory);
27546
27559
 
27547
27560
  this.fs_org = config.fs_org;
27548
27561
  this.fs_debug_mode = config.fs_debug_mode;
27549
27562
  this.name = "FULLSTORY";
27563
+ this.analytics = analytics;
27550
27564
  }
27551
27565
 
27552
27566
  _createClass(Fullstory, [{
@@ -27632,6 +27646,85 @@
27632
27646
  return g._w[y].apply(this, arguments);
27633
27647
  };
27634
27648
  })(window, document, window._fs_namespace, "script", "user");
27649
+
27650
+ var FULLSTORY = this.analytics.loadOnlyIntegrations.FULLSTORY; // Checking if crossDomainSupport is their or not.
27651
+
27652
+ if ((FULLSTORY === null || FULLSTORY === void 0 ? void 0 : FULLSTORY.crossDomainSupport) === true) {
27653
+ // This function will check if the customer hash is available or not in localStorage
27654
+ window._fs_identity = function () {
27655
+ if (window.localStorage) {
27656
+ var tata_customer_hash = window.localStorage.tata_customer_hash;
27657
+
27658
+ if (tata_customer_hash) {
27659
+ return {
27660
+ uid: tata_customer_hash,
27661
+ displayName: tata_customer_hash
27662
+ };
27663
+ }
27664
+ } else {
27665
+ logger.debug("Unable to access locaStorage");
27666
+ }
27667
+
27668
+ return null;
27669
+ };
27670
+
27671
+ (function () {
27672
+ function fs(api) {
27673
+ if (!window._fs_namespace) {
27674
+ console.error('FullStory unavailable, window["_fs_namespace"] must be defined');
27675
+ return undefined;
27676
+ }
27677
+
27678
+ return api ? window[window._fs_namespace][api] : window[window._fs_namespace];
27679
+ }
27680
+
27681
+ function waitUntil(predicateFn, callbackFn, timeout, timeoutFn) {
27682
+ var totalTime = 0;
27683
+ var delay = 64;
27684
+
27685
+ var resultFn = function resultFn() {
27686
+ if (typeof predicateFn === "function" && predicateFn()) {
27687
+ callbackFn();
27688
+ return;
27689
+ }
27690
+
27691
+ delay = Math.min(delay * 2, 1024);
27692
+
27693
+ if (totalTime > timeout) {
27694
+ if (timeoutFn) {
27695
+ timeoutFn();
27696
+ }
27697
+ }
27698
+
27699
+ totalTime += delay;
27700
+ setTimeout(resultFn, delay);
27701
+ };
27702
+
27703
+ resultFn();
27704
+ } // Checking if timeout is provided or not.
27705
+
27706
+
27707
+ var timeout = FULLSTORY.timeout || 2000;
27708
+
27709
+ function identify() {
27710
+ if (typeof window._fs_identity === "function") {
27711
+ var userVars = window._fs_identity();
27712
+
27713
+ if (_typeof(userVars) === "object" && typeof userVars.uid === "string") {
27714
+ fs("setUserVars")(userVars);
27715
+ fs("restart")();
27716
+ } else {
27717
+ fs("log")("error", "FS.setUserVars requires an object that contains uid");
27718
+ }
27719
+ } else {
27720
+ fs("log")("error", 'window["_fs_identity"] function not found');
27721
+ }
27722
+ }
27723
+
27724
+ fs("shutdown")();
27725
+ waitUntil(window._fs_identity, identify, timeout, fs("restart"));
27726
+ })();
27727
+ }
27635
27728
  }
27636
27729
  }, {
27637
27730
  key: "page",
@@ -29280,12 +29373,16 @@
29280
29373
 
29281
29374
  this.containerID = config.containerID;
29282
29375
  this.name = "GOOGLETAGMANAGER";
29376
+ this.serverUrl = config.serverUrl;
29283
29377
  }
29284
29378
 
29285
29379
  _createClass(GoogleTagManager, [{
29286
29380
  key: "init",
29287
29381
  value: function init() {
29288
29382
  logger.debug("===in init GoogleTagManager===");
29383
+ var defaultUrl = "https://www.googletagmanager.com"; // ref: https://developers.google.com/tag-platform/tag-manager/server-side/send-data#update_the_gtmjs_source_domain
29384
+
29385
+ window.finalUrl = this.serverUrl ? this.serverUrl : defaultUrl;
29289
29386
 
29290
29387
  (function (w, d, s, l, i) {
29291
29388
  w[l] = w[l] || [];
@@ -29297,7 +29394,7 @@
29297
29394
  var j = d.createElement(s);
29298
29395
  var dl = l !== "dataLayer" ? "&l=".concat(l) : "";
29299
29396
  j.async = true;
29300
- j.src = "https://www.googletagmanager.com/gtm.js?id=".concat(i).concat(dl);
29397
+ j.src = "".concat(window.finalUrl, "/gtm.js?id=").concat(i).concat(dl);
29301
29398
  f.parentNode.insertBefore(j, f);
29302
29399
  })(window, document, "script", "dataLayer", this.containerID);
29303
29400
  }
@@ -29485,8 +29582,7 @@
29485
29582
  function Hotjar(config) {
29486
29583
  _classCallCheck(this, Hotjar);
29487
29584
 
29488
- this.siteId = config.siteID; // 1549611
29489
-
29585
+ this.siteId = config.siteID;
29490
29586
  this.name = "HOTJAR";
29491
29587
  this._ready = false;
29492
29588
  }
@@ -29494,6 +29590,7 @@
29494
29590
  _createClass(Hotjar, [{
29495
29591
  key: "init",
29496
29592
  value: function init() {
29593
+ logger.debug("===In init Hotjar===");
29497
29594
  window.hotjarSiteId = this.siteId;
29498
29595
 
29499
29596
  (function (h, o, t, j, a, r) {
@@ -29513,11 +29610,11 @@
29513
29610
  })(window, document, "https://static.hotjar.com/c/hotjar-", ".js?sv=");
29514
29611
 
29515
29612
  this._ready = true;
29516
- logger.debug("===in init Hotjar===");
29517
29613
  }
29518
29614
  }, {
29519
29615
  key: "identify",
29520
29616
  value: function identify(rudderElement) {
29617
+ logger.debug("===In Hotjar identify===");
29521
29618
  var userId = rudderElement.message.userId || rudderElement.message.anonymousId;
29522
29619
 
29523
29620
  if (!userId) {
@@ -29531,21 +29628,34 @@
29531
29628
  }, {
29532
29629
  key: "track",
29533
29630
  value: function track(rudderElement) {
29534
- logger.debug("[Hotjar] track:: method not supported");
29631
+ logger.debug("===In Hotjar track===");
29632
+ var event = rudderElement.message.event;
29633
+
29634
+ if (!event) {
29635
+ logger.error("Event name not present");
29636
+ return;
29637
+ } // event name must not exceed 750 characters and can only contain alphanumeric, underscores, and dashes.
29638
+ // Ref - https://help.hotjar.com/hc/en-us/articles/4405109971095#the-events-api-call
29639
+
29640
+
29641
+ window.hj("event", event.replace(/\s\s+/g, " ").substring(0, 750).replaceAll(" ", "_"));
29535
29642
  }
29536
29643
  }, {
29537
29644
  key: "page",
29538
- value: function page(rudderElement) {
29645
+ value: function page() {
29646
+ logger.debug("===In Hotjar page===");
29539
29647
  logger.debug("[Hotjar] page:: method not supported");
29540
29648
  }
29541
29649
  }, {
29542
29650
  key: "isLoaded",
29543
29651
  value: function isLoaded() {
29652
+ logger.debug("===In isLoaded Hotjar===");
29544
29653
  return this._ready;
29545
29654
  }
29546
29655
  }, {
29547
29656
  key: "isReady",
29548
29657
  value: function isReady() {
29658
+ logger.debug("===In isReady Hotjar===");
29549
29659
  return this._ready;
29550
29660
  }
29551
29661
  }]);
@@ -32302,7 +32412,7 @@
32302
32412
  }();
32303
32413
 
32304
32414
  var eventMapping = [{
32305
- src: ["checkout step completed", "order completed"],
32415
+ src: ["order completed"],
32306
32416
  dest: "Checkout"
32307
32417
  }, {
32308
32418
  src: ["product added"],
@@ -32718,6 +32828,7 @@
32718
32828
  e._i.push([i, s, a]);
32719
32829
  }, e.__SV = 1);
32720
32830
  }(document, window.posthog || []);
32831
+ var POSTHOG = this.analytics.loadOnlyIntegrations.POSTHOG;
32721
32832
  var configObject = {
32722
32833
  api_host: this.yourInstance,
32723
32834
  autocapture: this.autocapture,
@@ -32727,6 +32838,10 @@
32727
32838
  disable_cookie: this.disableCookie
32728
32839
  };
32729
32840
 
32841
+ if (POSTHOG && POSTHOG.loaded) {
32842
+ configObject.loaded = POSTHOG.loaded;
32843
+ }
32844
+
32730
32845
  if (this.xhrHeaders && Object.keys(this.xhrHeaders).length > 0) {
32731
32846
  configObject.xhr_headers = this.xhrHeaders;
32732
32847
  }
@@ -34196,6 +34311,100 @@
34196
34311
  return PostAffiliatePro;
34197
34312
  }();
34198
34313
 
34314
+ var createUser = function createUser(message) {
34315
+ var user = {};
34316
+ user.key = message.userId || message.anonymousId;
34317
+ var traits = message.context.traits;
34318
+
34319
+ if (traits.anonymous !== undefined) {
34320
+ user.anonymous = traits.anonymous;
34321
+ }
34322
+
34323
+ if (traits.avatar !== undefined) user.avatar = traits.avatar;
34324
+ if (traits.country !== undefined) user.country = traits.country;
34325
+ if (traits.custom !== undefined) user.custom = traits.custom;
34326
+ if (traits.email !== undefined) user.email = traits.email;
34327
+ if (traits.firstName !== undefined) user.firstName = traits.firstName;
34328
+ if (traits.ip !== undefined) user.ip = traits.ip;
34329
+ if (traits.lastName !== undefined) user.lastName = traits.lastName;
34330
+ if (traits.name !== undefined) user.name = traits.name;
34331
+ if (traits.privateAttributeNames !== undefined) user.privateAttributeNames = traits.privateAttributeNames;
34332
+ if (traits.secondary !== undefined) user.secondary = traits.secondary;
34333
+ return user;
34334
+ };
34335
+
34336
+ var LaunchDarkly = /*#__PURE__*/function () {
34337
+ function LaunchDarkly(config) {
34338
+ _classCallCheck(this, LaunchDarkly);
34339
+
34340
+ this.name = "LaunchDarkly";
34341
+ this.clientSideId = config.clientSideId;
34342
+ }
34343
+
34344
+ _createClass(LaunchDarkly, [{
34345
+ key: "init",
34346
+ value: function init() {
34347
+ logger.debug("===in init LaunchDarkly===");
34348
+
34349
+ if (!this.clientSideId) {
34350
+ logger.error("".concat(this.name, " :: Unable to initialize destination - clientSideId is missing in config"));
34351
+ return;
34352
+ }
34353
+
34354
+ ScriptLoader(null, "https://unpkg.com/launchdarkly-js-client-sdk@2");
34355
+ }
34356
+ }, {
34357
+ key: "isLoaded",
34358
+ value: function isLoaded() {
34359
+ logger.debug("===In isLoaded LaunchDarkly===");
34360
+ return !!window.LDClient;
34361
+ }
34362
+ }, {
34363
+ key: "isReady",
34364
+ value: function isReady() {
34365
+ logger.debug("===In isReady LaunchDarkly===");
34366
+ return this.isLoaded();
34367
+ }
34368
+ }, {
34369
+ key: "identify",
34370
+ value: function identify(rudderElement) {
34371
+ var message = rudderElement.message;
34372
+ window.user = createUser(message);
34373
+
34374
+ if (window.ldclient) {
34375
+ window.ldclient.identify(window.user);
34376
+ } else {
34377
+ window.ldclient = window.LDClient.initialize(this.clientSideId, window.user);
34378
+ }
34379
+ }
34380
+ }, {
34381
+ key: "track",
34382
+ value: function track(rudderElement) {
34383
+ var _rudderElement$messag = rudderElement.message,
34384
+ event = _rudderElement$messag.event,
34385
+ properties = _rudderElement$messag.properties;
34386
+
34387
+ if (window.ldclient) {
34388
+ window.ldclient.track(event, properties);
34389
+ } else logger.error("=== In LaunchDarkly, track is not supported before identify ===");
34390
+ }
34391
+ }, {
34392
+ key: "alias",
34393
+ value: function alias(rudderElement) {
34394
+ var message = rudderElement.message;
34395
+ var newUser = {
34396
+ key: message.userId
34397
+ };
34398
+
34399
+ if (window.ldclient) {
34400
+ window.ldclient.alias(newUser, window.user);
34401
+ } else logger.error("=== In LaunchDarkly, alias is not supported before identify ===");
34402
+ }
34403
+ }]);
34404
+
34405
+ return LaunchDarkly;
34406
+ }();
34407
+
34199
34408
  // (config-plan name, native destination.name , exported integration name(this one below))
34200
34409
 
34201
34410
  var integrations = {
@@ -34242,7 +34451,8 @@
34242
34451
  TVSQUARED: TVSquared,
34243
34452
  VWO: VWO,
34244
34453
  GOOGLE_OPTIMIZE: GoogleOptimize,
34245
- POST_AFFILIATE_PRO: PostAffiliatePro
34454
+ POST_AFFILIATE_PRO: PostAffiliatePro,
34455
+ LAUNCHDARKLY: LaunchDarkly
34246
34456
  };
34247
34457
 
34248
34458
  // Application class
@@ -34252,7 +34462,7 @@
34252
34462
  this.build = "1.0.0";
34253
34463
  this.name = "RudderLabs JavaScript SDK";
34254
34464
  this.namespace = "com.rudderlabs.javascript";
34255
- this.version = "1.2.16";
34465
+ this.version = "1.3.2";
34256
34466
  });
34257
34467
 
34258
34468
  // Library information class
@@ -34260,7 +34470,7 @@
34260
34470
  _classCallCheck(this, RudderLibraryInfo);
34261
34471
 
34262
34472
  this.name = "RudderLabs JavaScript SDK";
34263
- this.version = "1.2.16";
34473
+ this.version = "1.3.2";
34264
34474
  }); // Operating System information class
34265
34475
 
34266
34476
 
@@ -37152,24 +37362,22 @@
37152
37362
  }, this);
37153
37363
  logger.debug("this.clientIntegrations: ", this.clientIntegrations); // intersection of config-plane native sdk destinations with sdk load time destination list
37154
37364
 
37155
- this.clientIntegrations = findAllEnabledDestinations(this.loadOnlyIntegrations, this.clientIntegrations); // Check if cookie consent manager is being set through load options
37365
+ this.clientIntegrations = findAllEnabledDestinations(this.loadOnlyIntegrations, this.clientIntegrations);
37366
+ var cookieConsent; // Call the cookie consent factory to initialize and return the type of cookie
37367
+ // consent being set. For now we only support OneTrust.
37156
37368
 
37157
- if (Object.keys(this.cookieConsentOptions).length) {
37158
- // Call the cookie consent factory to initialise and return the type of cookie
37159
- // consent being set. For now we only support OneTrust.
37160
- try {
37161
- var cookieConsent = CookieConsentFactory.initialize(this.cookieConsentOptions); // If cookie consent object is return we filter according to consents given by user
37162
- // else we do not consider any filtering for cookie consent.
37369
+ try {
37370
+ cookieConsent = CookieConsentFactory.initialize(this.cookieConsentOptions);
37371
+ } catch (e) {
37372
+ logger.error(e);
37373
+ } // If cookie consent object is return we filter according to consents given by user
37374
+ // else we do not consider any filtering for cookie consent.
37163
37375
 
37164
- this.clientIntegrations = this.clientIntegrations.filter(function (intg) {
37165
- return integrations[intg.name] != undefined && (!cookieConsent || // check if cookieconsent object is present and then do filtering
37166
- cookieConsent && cookieConsent.isEnabled(intg.config));
37167
- });
37168
- } catch (e) {
37169
- logger.error(e);
37170
- }
37171
- }
37172
37376
 
37377
+ this.clientIntegrations = this.clientIntegrations.filter(function (intg) {
37378
+ return integrations[intg.name] != undefined && (!cookieConsent || // check if cookie consent object is present and then do filtering
37379
+ cookieConsent && cookieConsent.isEnabled(intg.config));
37380
+ });
37173
37381
  this.init(this.clientIntegrations);
37174
37382
  } catch (error) {
37175
37383
  handleError(error);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rudder-sdk-js",
3
- "version": "1.2.16",
3
+ "version": "1.3.2",
4
4
  "description": "RudderStack Javascript SDK",
5
5
  "main": "index.js",
6
6
  "types": "index.d.ts",