Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,6 @@ export class AmplitudeSessionPlugin extends EventPlugin {
this.eventSessionId = this.sessionId;
}

if (eventName === AMP_SESSION_END_EVENT) {
console.log(`[AmplitudeSession] EndSession = ${this.eventSessionId}`);
}

if (
eventName.startsWith('Amplitude') ||
eventName === AMP_SESSION_START_EVENT ||
Expand Down Expand Up @@ -197,7 +193,7 @@ export class AmplitudeSessionPlugin extends EventPlugin {
...event,
integrations: {
...integrations,
[this.key]: { session_id: this.sessionId },
[this.key]: { session_id: this.eventSessionId },
},
};
};
Expand Down Expand Up @@ -255,8 +251,6 @@ export class AmplitudeSessionPlugin extends EventPlugin {
this.eventSessionId === -1 ? newSessionId : this.eventSessionId;
this.lastEventTime = newSessionId;

console.log(`[AmplitudeSession] startNewSession -> ${newSessionId}`);

await this.trackSessionStart(newSessionId);
}

Expand All @@ -276,8 +270,6 @@ export class AmplitudeSessionPlugin extends EventPlugin {
return;
}

console.log(`[AmplitudeSession] endSession -> ${this.sessionId}`);

this.analytics?.track(AMP_SESSION_END_EVENT, {
integrations: {
[this.key]: { session_id: sessionId },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -746,6 +746,34 @@ describe('AmplitudeSessionPlugin', () => {
});
});

it('should use eventSessionId for event enrichment during transition', async () => {
const baseTime = Date.now();
jest.setSystemTime(baseTime);

// Set up a session where eventSessionId differs from sessionId
// (simulates mid-transition state where new session has started but
// eventSessionId still points to the old session)
plugin['_sessionId'] = baseTime;
plugin['_eventSessionId'] = baseTime - 50000;
plugin['_lastEventTime'] = baseTime - 1000;

const mockEvent: TrackEventType = {
type: EventType.TrackEvent,
event: 'test_event',
properties: {},
messageId: 'msg-1',
timestamp: '2023-01-01T00:00:00.000Z',
anonymousId: 'anon-1',
};

const result = await plugin.execute(mockEvent);

// insertSession should use eventSessionId, not sessionId
expect(result.integrations?.['Actions Amplitude']).toEqual({
session_id: baseTime - 50000,
});
});

it('should NOT modify events when session_id already exists', async () => {
const mockEvent: TrackEventType = {
type: EventType.TrackEvent,
Expand Down
Loading