How do we set session in Amplitude while using Segment in Cloud Mode?
There are 2 ways to sessionize your data in Amplitude if you are using Segment cloud mode.
-
Amplitude’s Best Practices:
The first method is where we are passed in sessionId into the integrations object.
Sample code:
1 2 3 4 5 6 7 8 9
analytics.track({ userId: 'samplitude1234' event: 'subscription renewed', integrations: { 'Amplitude': { 'session_id': 1531845205000 // Start time of session in milliseconds since epoch } } });
The second option is to send your own custom session property, which would be a regular property in your track calls:
1 2 3 4 5
analytics.track('Gold Payment Option Clicked', { payment type: 'credit card', membership type: 'individual', grx_session_id: 'eda546f4-9ea6-4d40-a3b2-54491ac7a18a' });
Either option works for Amplitude.
It is more so dependent on which one makes most sense for your team from a technical standpoint. The first option requires customizing Segment's integrations object and also conforming to the timestamp value. The second option treats the session property like any other Segment property and you do not need to conform to timestamp (e.g. in the example we have a random UUID).