amplitude / Amplitude-JavaScript

JavaScript SDK for Amplitude
MIT License
315 stars 133 forks source link

Please add setSession to Options #373

Open kimhecan opened 3 years ago

kimhecan commented 3 years ago

Summary

current code is (as-is)

  var event = {
      device_id: this.options.deviceId,
      user_id: this.options.userId,
      timestamp: eventTime,
      event_id: eventId,
      session_id: this._sessionId || -1,
      event_type: eventType ...
}

updated code is(to-be)

    var event = {
      device_id: this.options.deviceId,
      user_id: this.options.userId,
      timestamp: eventTime,
      event_id: eventId,
      session_id: this.options.sessionId || this._sessionId || -1,
      event_type: eventType...
}

using like

  amplitude
    .getInstance()
    .init('1231231231', userId, {
       sessionId: 'customId'      
       saveEvents: true,
      includeUtm: true,
      includeReferrer: true
    });

Motivations

In some cases like webView, web developers need to set a session ID obtaining from app when init amplitude and request it to amplitude.

kevinpagtakhan commented 2 years ago

@kimhecan Thanks for the creating an issue and putting up this suggestion! Do you feel strongly about setting the sessionId on init()? An alternative to that is calling setSessionId() after calling init();

For example:

amplitude.init(API_KEY)
amplitude.getInstance().setSessionId(12341234);