From ef0f056a7d3efee8831f5fe2c60684f89bfd317b Mon Sep 17 00:00:00 2001 From: kdastan Date: Tue, 9 Nov 2021 20:02:08 +0600 Subject: [PATCH] feat: add onNewSession function --- src/amplitude-client.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/amplitude-client.js b/src/amplitude-client.js index 701d2934..0a6e8c13 100644 --- a/src/amplitude-client.js +++ b/src/amplitude-client.js @@ -44,6 +44,7 @@ var AmplitudeClient = function AmplitudeClient(instanceName) { this._sending = false; this._updateScheduled = false; this._onInit = []; + this._onNewSession = []; // event meta data this._eventId = 0; @@ -172,6 +173,9 @@ AmplitudeClient.prototype.init = function init(apiKey, opt_userId, opt_config, o if (this.options.unsetParamsReferrerOnNewSession) { this._unsetUTMParams(); } + for (let i = 0; i < this._onNewSession.length; i++) { + this._onNewSession[i](this); + } this._newSession = true; this._sessionId = now; @@ -479,6 +483,10 @@ AmplitudeClient.prototype.onInit = function (callback) { } }; +AmplitudeClient.prototype.onNewSessionStart = function (callback) { + this._onNewSession.push(callback) +} + /** * Returns the id of the current session. * @public