Skip to content

Commit c7e90ab

Browse files
author
Daniel Jih
committed
specify custom session id with method and in init config
1 parent 673b76d commit c7e90ab

File tree

4 files changed

+37
-3
lines changed

4 files changed

+37
-3
lines changed

amplitude.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -568,6 +568,9 @@ AmplitudeClient.prototype.init = function init(apiKey, opt_userId, opt_config, o
568568
this.options.userId = (type(opt_userId) === 'string' && !utils.isEmptyString(opt_userId) && opt_userId) ||
569569
this.options.userId || null;
570570

571+
// if custom session id specified in config, override what is stored in cookie
572+
this._sessionId = this.options.sessionId > 0 ? this.options.sessionId : this._sessionId;
573+
571574
// load unsent events and identifies before any attempt to log new ones
572575
if (this.options.saveEvents) {
573576
this._unsentEvents = this._loadSavedUnsentEvents(this.options.unsentKey);
@@ -1065,6 +1068,19 @@ AmplitudeClient.prototype.setDomain = function setDomain(domain) {
10651068
}
10661069
};
10671070

1071+
AmplitudeClient.prototype.setSessionId = function setSessionId(sessionId) {
1072+
if (!utils.validateInput(sessionId, 'sessionId', 'number')) {
1073+
return;
1074+
}
1075+
1076+
try {
1077+
this._sessionId = sessionId;
1078+
_saveCookieData(this);
1079+
} catch (e) {
1080+
utils.log(e);
1081+
}
1082+
};
1083+
10681084
/**
10691085
* Sets an identifier for the current user.
10701086
* @public
@@ -5005,6 +5021,7 @@ module.exports = {
50055021
includeGclid: false,
50065022
saveParamsReferrerOncePerSession: true,
50075023
deviceIdFromUrlParam: false,
5024+
sessionId: 0,
50085025
};
50095026

50105027
}, {"./language":29}],

amplitude.min.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/amplitude-client.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,9 @@ AmplitudeClient.prototype.init = function init(apiKey, opt_userId, opt_config, o
8787
this.options.userId = (type(opt_userId) === 'string' && !utils.isEmptyString(opt_userId) && opt_userId) ||
8888
this.options.userId || null;
8989

90+
// if custom session id specified in config, override what is stored in cookie
91+
this._sessionId = this.options.sessionId > 0 ? this.options.sessionId : this._sessionId;
92+
9093
// load unsent events and identifies before any attempt to log new ones
9194
if (this.options.saveEvents) {
9295
this._unsentEvents = this._loadSavedUnsentEvents(this.options.unsentKey);
@@ -584,6 +587,19 @@ AmplitudeClient.prototype.setDomain = function setDomain(domain) {
584587
}
585588
};
586589

590+
AmplitudeClient.prototype.setSessionId = function setSessionId(sessionId) {
591+
if (!utils.validateInput(sessionId, 'sessionId', 'number')) {
592+
return;
593+
}
594+
595+
try {
596+
this._sessionId = sessionId;
597+
_saveCookieData(this);
598+
} catch (e) {
599+
utils.log(e);
600+
}
601+
};
602+
587603
/**
588604
* Sets an identifier for the current user.
589605
* @public

src/options.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,5 @@ module.exports = {
2424
includeGclid: false,
2525
saveParamsReferrerOncePerSession: true,
2626
deviceIdFromUrlParam: false,
27+
sessionId: 0,
2728
};

0 commit comments

Comments
 (0)