rudder-sdk-js 2.3.8 → 2.4.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.
- package/index.d.ts +13 -1
- package/index.js +278 -40
- package/package.json +1 -1
package/index.d.ts
CHANGED
@@ -49,6 +49,16 @@ declare module "rudder-sdk-js" {
|
|
49
49
|
};
|
50
50
|
}
|
51
51
|
|
52
|
+
/**
|
53
|
+
* Represents the options parameter for anonymousId
|
54
|
+
*/
|
55
|
+
interface anonymousIdOptions {
|
56
|
+
autoCapture?: {
|
57
|
+
enabled?: boolean;
|
58
|
+
source?: string;
|
59
|
+
};
|
60
|
+
}
|
61
|
+
|
52
62
|
/**
|
53
63
|
* Represents the options parameter in the load API
|
54
64
|
*/
|
@@ -74,6 +84,7 @@ declare module "rudder-sdk-js" {
|
|
74
84
|
useBeacon?: boolean; // Defaults to false
|
75
85
|
beaconQueueOptions?: beaconQueueOptions;
|
76
86
|
cookieConsentManager?: cookieConsentManager;
|
87
|
+
anonymousIdOptions?: anonymousIdOptions;
|
77
88
|
}
|
78
89
|
|
79
90
|
/**
|
@@ -399,7 +410,7 @@ declare module "rudder-sdk-js" {
|
|
399
410
|
/**
|
400
411
|
* To get anonymousId set in the SDK
|
401
412
|
*/
|
402
|
-
function getAnonymousId(): string;
|
413
|
+
function getAnonymousId(options?: anonymousIdOptions): string;
|
403
414
|
|
404
415
|
/**
|
405
416
|
* To set anonymousId
|
@@ -429,6 +440,7 @@ declare module "rudder-sdk-js" {
|
|
429
440
|
queueOptions,
|
430
441
|
apiObject,
|
431
442
|
apiCallback,
|
443
|
+
anonymousIdOptions,
|
432
444
|
load,
|
433
445
|
ready,
|
434
446
|
reset,
|
package/index.js
CHANGED
@@ -4371,6 +4371,126 @@
|
|
4371
4371
|
}
|
4372
4372
|
})(componentUrl);
|
4373
4373
|
|
4374
|
+
var isobject = function isObject(val) {
|
4375
|
+
return val != null && _typeof(val) === 'object' && Array.isArray(val) === false;
|
4376
|
+
};
|
4377
|
+
|
4378
|
+
/*!
|
4379
|
+
* get-value <https://github.com/jonschlinkert/get-value>
|
4380
|
+
*
|
4381
|
+
* Copyright (c) 2014-2018, Jon Schlinkert.
|
4382
|
+
* Released under the MIT License.
|
4383
|
+
*/
|
4384
|
+
var isObject$1 = isobject;
|
4385
|
+
|
4386
|
+
var getValue = function getValue(target, path, options) {
|
4387
|
+
if (!isObject$1(options)) {
|
4388
|
+
options = {
|
4389
|
+
default: options
|
4390
|
+
};
|
4391
|
+
}
|
4392
|
+
|
4393
|
+
if (!isValidObject(target)) {
|
4394
|
+
return typeof options.default !== 'undefined' ? options.default : target;
|
4395
|
+
}
|
4396
|
+
|
4397
|
+
if (typeof path === 'number') {
|
4398
|
+
path = String(path);
|
4399
|
+
}
|
4400
|
+
|
4401
|
+
var isArray = Array.isArray(path);
|
4402
|
+
var isString = typeof path === 'string';
|
4403
|
+
var splitChar = options.separator || '.';
|
4404
|
+
var joinChar = options.joinChar || (typeof splitChar === 'string' ? splitChar : '.');
|
4405
|
+
|
4406
|
+
if (!isString && !isArray) {
|
4407
|
+
return target;
|
4408
|
+
}
|
4409
|
+
|
4410
|
+
if (isString && path in target) {
|
4411
|
+
return isValid(path, target, options) ? target[path] : options.default;
|
4412
|
+
}
|
4413
|
+
|
4414
|
+
var segs = isArray ? path : split(path, splitChar, options);
|
4415
|
+
var len = segs.length;
|
4416
|
+
var idx = 0;
|
4417
|
+
|
4418
|
+
do {
|
4419
|
+
var prop = segs[idx];
|
4420
|
+
|
4421
|
+
if (typeof prop === 'number') {
|
4422
|
+
prop = String(prop);
|
4423
|
+
}
|
4424
|
+
|
4425
|
+
while (prop && prop.slice(-1) === '\\') {
|
4426
|
+
prop = join([prop.slice(0, -1), segs[++idx] || ''], joinChar, options);
|
4427
|
+
}
|
4428
|
+
|
4429
|
+
if (prop in target) {
|
4430
|
+
if (!isValid(prop, target, options)) {
|
4431
|
+
return options.default;
|
4432
|
+
}
|
4433
|
+
|
4434
|
+
target = target[prop];
|
4435
|
+
} else {
|
4436
|
+
var hasProp = false;
|
4437
|
+
var n = idx + 1;
|
4438
|
+
|
4439
|
+
while (n < len) {
|
4440
|
+
prop = join([prop, segs[n++]], joinChar, options);
|
4441
|
+
|
4442
|
+
if (hasProp = prop in target) {
|
4443
|
+
if (!isValid(prop, target, options)) {
|
4444
|
+
return options.default;
|
4445
|
+
}
|
4446
|
+
|
4447
|
+
target = target[prop];
|
4448
|
+
idx = n - 1;
|
4449
|
+
break;
|
4450
|
+
}
|
4451
|
+
}
|
4452
|
+
|
4453
|
+
if (!hasProp) {
|
4454
|
+
return options.default;
|
4455
|
+
}
|
4456
|
+
}
|
4457
|
+
} while (++idx < len && isValidObject(target));
|
4458
|
+
|
4459
|
+
if (idx === len) {
|
4460
|
+
return target;
|
4461
|
+
}
|
4462
|
+
|
4463
|
+
return options.default;
|
4464
|
+
};
|
4465
|
+
|
4466
|
+
function join(segs, joinChar, options) {
|
4467
|
+
if (typeof options.join === 'function') {
|
4468
|
+
return options.join(segs);
|
4469
|
+
}
|
4470
|
+
|
4471
|
+
return segs[0] + joinChar + segs[1];
|
4472
|
+
}
|
4473
|
+
|
4474
|
+
function split(path, splitChar, options) {
|
4475
|
+
if (typeof options.split === 'function') {
|
4476
|
+
return options.split(path);
|
4477
|
+
}
|
4478
|
+
|
4479
|
+
return path.split(splitChar);
|
4480
|
+
}
|
4481
|
+
|
4482
|
+
function isValid(key, target, options) {
|
4483
|
+
if (typeof options.isValid === 'function') {
|
4484
|
+
return options.isValid(key, target);
|
4485
|
+
}
|
4486
|
+
|
4487
|
+
return true;
|
4488
|
+
}
|
4489
|
+
|
4490
|
+
function isValidObject(val) {
|
4491
|
+
return isObject$1(val) || Array.isArray(val) || typeof val === 'function';
|
4492
|
+
}
|
4493
|
+
|
4374
4494
|
var LOG_LEVEL_INFO = 1;
|
4375
4495
|
var LOG_LEVEL_DEBUG = 2;
|
4376
4496
|
var LOG_LEVEL_WARN = 3;
|
@@ -4709,7 +4829,7 @@
|
|
4709
4829
|
|
4710
4830
|
// Reserved Keywords for properties/traits
|
4711
4831
|
var ReservedPropertyKeywords = ["anonymous_id", "id", "sent_at", "received_at", "timestamp", "original_timestamp", "event_text", "event"]; // ECommerce Parameter Names Enumeration
|
4712
|
-
var CONFIG_URL = "https://api.rudderlabs.com/sourceConfig/?p=npm&v=2.
|
4832
|
+
var CONFIG_URL = "https://api.rudderlabs.com/sourceConfig/?p=npm&v=2.4.2";
|
4713
4833
|
var CDN_INT_DIR = "js-integrations";
|
4714
4834
|
var DEST_SDK_BASE_URL = "https://cdn.rudderlabs.com/v1.1/".concat(CDN_INT_DIR);
|
4715
4835
|
var MAX_WAIT_FOR_INTEGRATION_LOAD = 10000;
|
@@ -9230,6 +9350,7 @@
|
|
9230
9350
|
|
9231
9351
|
this._options = {};
|
9232
9352
|
this.options(options);
|
9353
|
+
this.isSupportAvailable = this.checkSupportAvailability();
|
9233
9354
|
}
|
9234
9355
|
/**
|
9235
9356
|
*
|
@@ -9251,15 +9372,7 @@
|
|
9251
9372
|
path: "/",
|
9252
9373
|
domain: domain,
|
9253
9374
|
samesite: "Lax"
|
9254
|
-
});
|
9255
|
-
|
9256
|
-
this.set("test_rudder", true);
|
9257
|
-
|
9258
|
-
if (!this.get("test_rudder")) {
|
9259
|
-
this._options.domain = null;
|
9260
|
-
}
|
9261
|
-
|
9262
|
-
this.remove("test_rudder");
|
9375
|
+
});
|
9263
9376
|
}
|
9264
9377
|
/**
|
9265
9378
|
*
|
@@ -9303,6 +9416,24 @@
|
|
9303
9416
|
return false;
|
9304
9417
|
}
|
9305
9418
|
}
|
9419
|
+
/**
|
9420
|
+
* Function to check cookie support exists or not
|
9421
|
+
* @returns boolean
|
9422
|
+
*/
|
9423
|
+
|
9424
|
+
}, {
|
9425
|
+
key: "checkSupportAvailability",
|
9426
|
+
value: function checkSupportAvailability() {
|
9427
|
+
var name = "test_rudder_cookie";
|
9428
|
+
this.set(name, true);
|
9429
|
+
|
9430
|
+
if (this.get(name)) {
|
9431
|
+
this.remove(name);
|
9432
|
+
return true;
|
9433
|
+
}
|
9434
|
+
|
9435
|
+
return false;
|
9436
|
+
}
|
9306
9437
|
}]);
|
9307
9438
|
|
9308
9439
|
return CookieLocal;
|
@@ -10647,6 +10778,9 @@
|
|
10647
10778
|
prefix: "RudderEncrypt:",
|
10648
10779
|
key: "Rudder"
|
10649
10780
|
};
|
10781
|
+
var anonymousIdKeyMap = {
|
10782
|
+
segment: "ajs_anonymous_id"
|
10783
|
+
};
|
10650
10784
|
/**
|
10651
10785
|
* Json stringify the given value
|
10652
10786
|
* @param {*} value
|
@@ -10720,10 +10854,7 @@
|
|
10720
10854
|
_classCallCheck(this, Storage);
|
10721
10855
|
|
10722
10856
|
// First try setting the storage to cookie else to localstorage
|
10723
|
-
Cookie.
|
10724
|
-
|
10725
|
-
if (Cookie.get("rudder_cookies")) {
|
10726
|
-
Cookie.remove("rudder_cookies");
|
10857
|
+
if (Cookie.isSupportAvailable) {
|
10727
10858
|
this.storage = Cookie;
|
10728
10859
|
return;
|
10729
10860
|
} // localStorage is enabled.
|
@@ -10886,14 +11017,103 @@
|
|
10886
11017
|
value: function getGroupTraits() {
|
10887
11018
|
return this.getItem(defaults$1.group_storage_trait);
|
10888
11019
|
}
|
11020
|
+
/**
|
11021
|
+
* Function to fetch anonymousId from external source
|
11022
|
+
* @param {string} key source of the anonymousId
|
11023
|
+
* @returns string
|
11024
|
+
*/
|
11025
|
+
|
11026
|
+
}, {
|
11027
|
+
key: "fetchExternalAnonymousId",
|
11028
|
+
value: function fetchExternalAnonymousId(source) {
|
11029
|
+
var anonId;
|
11030
|
+
var key = source.toLowerCase();
|
11031
|
+
|
11032
|
+
if (!Object.keys(anonymousIdKeyMap).includes(key)) {
|
11033
|
+
return anonId;
|
11034
|
+
}
|
11035
|
+
|
11036
|
+
switch (key) {
|
11037
|
+
case "segment":
|
11038
|
+
/**
|
11039
|
+
* First check the local storage for anonymousId
|
11040
|
+
* Ref: https://segment.com/docs/connections/sources/catalog/libraries/website/javascript/#identify
|
11041
|
+
*/
|
11042
|
+
if (Store$2.enabled) {
|
11043
|
+
anonId = Store$2.get(anonymousIdKeyMap[key]);
|
11044
|
+
} // If anonymousId is not present in local storage and check cookie support exists
|
11045
|
+
// fetch it from cookie
|
11046
|
+
|
11047
|
+
|
11048
|
+
if (!anonId && Cookie.IsCookieSupported()) {
|
11049
|
+
anonId = Cookie.get(anonymousIdKeyMap[key]);
|
11050
|
+
}
|
11051
|
+
|
11052
|
+
return anonId;
|
11053
|
+
|
11054
|
+
default:
|
11055
|
+
return anonId;
|
11056
|
+
}
|
11057
|
+
}
|
10889
11058
|
/**
|
10890
11059
|
* get stored anonymous id
|
11060
|
+
*
|
11061
|
+
* Use cases:
|
11062
|
+
* 1. getAnonymousId() -> anonymousIdOptions is undefined this function will return rl_anonymous_id
|
11063
|
+
* if present otherwise undefined
|
11064
|
+
*
|
11065
|
+
* 2. getAnonymousId(anonymousIdOptions) -> In case anonymousIdOptions is present this function will check
|
11066
|
+
* if rl_anonymous_id is present then it will return that
|
11067
|
+
*
|
11068
|
+
* otherwise it will validate the anonymousIdOptions and try to fetch the anonymous Id from the provided source.
|
11069
|
+
* Finally if no anonymous Id is present in the source it will return undefined.
|
11070
|
+
*
|
11071
|
+
* anonymousIdOptions example:
|
11072
|
+
* {
|
11073
|
+
autoCapture: {
|
11074
|
+
enabled: true,
|
11075
|
+
source: "segment",
|
11076
|
+
},
|
11077
|
+
}
|
11078
|
+
*
|
10891
11079
|
*/
|
10892
11080
|
|
10893
11081
|
}, {
|
10894
11082
|
key: "getAnonymousId",
|
10895
|
-
value: function getAnonymousId() {
|
10896
|
-
|
11083
|
+
value: function getAnonymousId(anonymousIdOptions) {
|
11084
|
+
// fetch the rl_anonymous_id from storage
|
11085
|
+
var rlAnonymousId = parse(decryptValue(this.storage.get(defaults$1.user_storage_anonymousId)));
|
11086
|
+
/**
|
11087
|
+
* If RS's anonymous ID is available, return from here.
|
11088
|
+
*
|
11089
|
+
* The user, while migrating from a different analytics SDK,
|
11090
|
+
* will only need to auto-capture the anonymous ID when the RS SDK
|
11091
|
+
* loads for the first time.
|
11092
|
+
*
|
11093
|
+
* The captured anonymous ID would be available in RS's persistent storage
|
11094
|
+
* for all the subsequent SDK runs.
|
11095
|
+
* So, instead of always grabbing the ID from the migration source when
|
11096
|
+
* the options are specified, it is first checked in the RS's persistent storage.
|
11097
|
+
*
|
11098
|
+
* Moreover, the user can also clear the anonymous ID from the storage via
|
11099
|
+
* the 'reset' API, which renders the migration source's data useless.
|
11100
|
+
*/
|
11101
|
+
|
11102
|
+
if (rlAnonymousId) {
|
11103
|
+
return rlAnonymousId;
|
11104
|
+
} // validate the provided anonymousIdOptions argument
|
11105
|
+
|
11106
|
+
|
11107
|
+
var source = getValue(anonymousIdOptions, "autoCapture.source");
|
11108
|
+
|
11109
|
+
if (getValue(anonymousIdOptions, "autoCapture.enabled") === true && typeof source === "string") {
|
11110
|
+
// fetch the anonymousId from the external source
|
11111
|
+
// ex - segment
|
11112
|
+
var anonId = this.fetchExternalAnonymousId(source);
|
11113
|
+
if (anonId) return anonId; // return anonymousId if present
|
11114
|
+
}
|
11115
|
+
|
11116
|
+
return rlAnonymousId; // return undefined
|
10897
11117
|
}
|
10898
11118
|
/**
|
10899
11119
|
* get stored initial referrer
|
@@ -11177,23 +11397,32 @@
|
|
11177
11397
|
allValue = sdkSuppliedIntegrations.All;
|
11178
11398
|
}
|
11179
11399
|
|
11180
|
-
var intgData =
|
11400
|
+
var intgData = [];
|
11181
11401
|
|
11182
11402
|
if (typeof configPlaneEnabledIntegrations[0] === "string") {
|
11183
11403
|
configPlaneEnabledIntegrations.forEach(function (intg) {
|
11184
|
-
intgData
|
11404
|
+
intgData.push({
|
11405
|
+
intgName: intg,
|
11406
|
+
intObj: intg
|
11407
|
+
});
|
11185
11408
|
});
|
11186
11409
|
} else if (_typeof(configPlaneEnabledIntegrations[0]) === "object") {
|
11187
11410
|
configPlaneEnabledIntegrations.forEach(function (intg) {
|
11188
|
-
intgData
|
11411
|
+
intgData.push({
|
11412
|
+
intgName: intg.name,
|
11413
|
+
intObj: intg
|
11414
|
+
});
|
11189
11415
|
});
|
11190
11416
|
}
|
11191
11417
|
|
11192
|
-
|
11418
|
+
intgData.forEach(function (_ref) {
|
11419
|
+
var intgName = _ref.intgName,
|
11420
|
+
intObj = _ref.intObj;
|
11421
|
+
|
11193
11422
|
if (!allValue) {
|
11194
11423
|
// All false ==> check if intg true supplied
|
11195
11424
|
if (sdkSuppliedIntegrations[intgName] != undefined && sdkSuppliedIntegrations[intgName] == true) {
|
11196
|
-
enabledList.push(
|
11425
|
+
enabledList.push(intObj);
|
11197
11426
|
}
|
11198
11427
|
} else {
|
11199
11428
|
// All true ==> intg true by default
|
@@ -11204,7 +11433,7 @@
|
|
11204
11433
|
}
|
11205
11434
|
|
11206
11435
|
if (intgValue) {
|
11207
|
-
enabledList.push(
|
11436
|
+
enabledList.push(intObj);
|
11208
11437
|
}
|
11209
11438
|
}
|
11210
11439
|
});
|
@@ -11306,7 +11535,7 @@
|
|
11306
11535
|
this.build = "1.0.0";
|
11307
11536
|
this.name = "RudderLabs JavaScript SDK";
|
11308
11537
|
this.namespace = "com.rudderlabs.javascript";
|
11309
|
-
this.version = "2.
|
11538
|
+
this.version = "2.4.2";
|
11310
11539
|
});
|
11311
11540
|
|
11312
11541
|
/* eslint-disable max-classes-per-file */
|
@@ -11315,7 +11544,7 @@
|
|
11315
11544
|
_classCallCheck(this, RudderLibraryInfo);
|
11316
11545
|
|
11317
11546
|
this.name = "RudderLabs JavaScript SDK";
|
11318
|
-
this.version = "2.
|
11547
|
+
this.version = "2.4.2";
|
11319
11548
|
}); // Operating System information class
|
11320
11549
|
|
11321
11550
|
|
@@ -11731,8 +11960,8 @@
|
|
11731
11960
|
*/
|
11732
11961
|
var byteToHex = [];
|
11733
11962
|
|
11734
|
-
for (var i = 0; i < 256; ++i) {
|
11735
|
-
byteToHex[i] = (i + 0x100).toString(16).substr(1);
|
11963
|
+
for (var i$1 = 0; i$1 < 256; ++i$1) {
|
11964
|
+
byteToHex[i$1] = (i$1 + 0x100).toString(16).substr(1);
|
11736
11965
|
}
|
11737
11966
|
|
11738
11967
|
function bytesToUuid$2(buf, offset) {
|
@@ -13594,7 +13823,7 @@
|
|
13594
13823
|
|
13595
13824
|
_createClass(Analytics, [{
|
13596
13825
|
key: "initializeUser",
|
13597
|
-
value: function initializeUser() {
|
13826
|
+
value: function initializeUser(anonymousIdOptions) {
|
13598
13827
|
// save once for storing older values to encrypted
|
13599
13828
|
this.userId = this.storage.getUserId() || "";
|
13600
13829
|
this.storage.setUserId(this.userId);
|
@@ -13604,7 +13833,7 @@
|
|
13604
13833
|
this.storage.setGroupId(this.groupId);
|
13605
13834
|
this.groupTraits = this.storage.getGroupTraits() || {};
|
13606
13835
|
this.storage.setGroupTraits(this.groupTraits);
|
13607
|
-
this.anonymousId = this.getAnonymousId();
|
13836
|
+
this.anonymousId = this.getAnonymousId(anonymousIdOptions);
|
13608
13837
|
this.storage.setAnonymousId(this.anonymousId);
|
13609
13838
|
}
|
13610
13839
|
}, {
|
@@ -14282,9 +14511,9 @@
|
|
14282
14511
|
}
|
14283
14512
|
}, {
|
14284
14513
|
key: "getAnonymousId",
|
14285
|
-
value: function getAnonymousId() {
|
14514
|
+
value: function getAnonymousId(anonymousIdOptions) {
|
14286
14515
|
// if (!this.loaded) return;
|
14287
|
-
this.anonymousId = this.storage.getAnonymousId();
|
14516
|
+
this.anonymousId = this.storage.getAnonymousId(anonymousIdOptions);
|
14288
14517
|
|
14289
14518
|
if (!this.anonymousId) {
|
14290
14519
|
this.setAnonymousId();
|
@@ -14423,7 +14652,7 @@
|
|
14423
14652
|
}
|
14424
14653
|
|
14425
14654
|
this.eventRepository.initialize(writeKey, serverUrl, options);
|
14426
|
-
this.initializeUser();
|
14655
|
+
this.initializeUser(options ? options.anonymousIdOptions : undefined);
|
14427
14656
|
this.setInitialPageProperties();
|
14428
14657
|
this.loaded = true;
|
14429
14658
|
|
@@ -14640,21 +14869,30 @@
|
|
14640
14869
|
|
14641
14870
|
instance.registerCallbacks(false);
|
14642
14871
|
var defaultMethod = "load";
|
14643
|
-
var argumentsArray = window.rudderanalytics
|
14872
|
+
var argumentsArray = window.rudderanalytics;
|
14873
|
+
var isValidArgsArray = Array.isArray(argumentsArray);
|
14644
14874
|
|
14645
|
-
|
14646
|
-
|
14647
|
-
|
14648
|
-
|
14649
|
-
|
14650
|
-
|
14875
|
+
if (isValidArgsArray) {
|
14876
|
+
/**
|
14877
|
+
* Iterate the buffered API calls until we find load call and
|
14878
|
+
* queue it first for processing
|
14879
|
+
*/
|
14880
|
+
var i = 0;
|
14651
14881
|
|
14652
|
-
argumentsArray.
|
14882
|
+
while (i < argumentsArray.length) {
|
14883
|
+
if (argumentsArray[i] && argumentsArray[i][0] === defaultMethod) {
|
14884
|
+
instance.toBeProcessedArray.push(argumentsArray[i]);
|
14885
|
+
argumentsArray.splice(i, 1);
|
14886
|
+
break;
|
14887
|
+
}
|
14888
|
+
|
14889
|
+
i += 1;
|
14890
|
+
}
|
14653
14891
|
} // parse querystring of the page url to send events
|
14654
14892
|
|
14655
14893
|
|
14656
14894
|
parseQueryString(window.location.search);
|
14657
|
-
if (
|
14895
|
+
if (isValidArgsArray) argumentsArray.forEach(function (x) {
|
14658
14896
|
return instance.toBeProcessedArray.push(x);
|
14659
14897
|
});
|
14660
14898
|
processDataInAnalyticsArray(instance);
|