Skip to content

Commit 3d773fe

Browse files
author
Sunita Prajapati
committed
refactor: removed unused code, comments and console logs
1 parent b9759e2 commit 3d773fe

File tree

1 file changed

+1
-67
lines changed

1 file changed

+1
-67
lines changed

packages/plugins/plugin-amplitudeSession/src/AmplitudeSessionPlugin.tsx

Lines changed: 1 addition & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import {
1616
import AsyncStorage from '@react-native-async-storage/async-storage';
1717
import { AppState } from 'react-native';
1818

19-
const MAX_SESSION_TIME_IN_MS = 60000;
19+
const MAX_SESSION_TIME_IN_MS = 300000;
2020
const SESSION_ID_KEY = 'previous_session_id';
2121
const LAST_EVENT_TIME_KEY = 'last_event_time';
2222
const AMP_SESSION_START_EVENT = 'session_start';
@@ -30,43 +30,33 @@ export class AmplitudeSessionPlugin extends EventPlugin {
3030
lastEventTime = -1;
3131
eventSessionId = -1;
3232
resetPending = false;
33-
//private sessionCreationInProgress = false;
3433

3534
configure = async (analytics: SegmentClient): Promise<void> => {
36-
console.log('configure');
3735
this.analytics = analytics;
3836
await this.loadSessionData();
3937
AppState.addEventListener('change', this.handleAppStateChange);
4038
};
4139

4240
update(settings: SegmentAPISettings, type: UpdateType) {
43-
console.log('update');
4441

4542
if (type !== UpdateType.initial) return;
4643
this.active = settings.integrations?.hasOwnProperty(this.key) ?? false;
4744
}
4845

4946
async execute(event: SegmentEvent) {
50-
console.log('execute');
5147

5248
if (!this.active) return event;
5349

5450
if (this.sessionId === -1 || this.lastEventTime === -1) {
55-
console.log('execute loadSessionData');
5651
await this.loadSessionData();
5752
}
58-
console.log('execute startNewSessionIfNecessary');
5953
await this.startNewSessionIfNecessary();
60-
61-
62-
6354
let result = event;
6455
switch (result.type) {
6556
case EventType.IdentifyEvent:
6657
result = this.identify(result);
6758
break;
6859
case EventType.TrackEvent:
69-
console.log('EventType.TrackEvent');
7060
result = this.track(result);
7161
break;
7262
case EventType.ScreenEvent:
@@ -81,8 +71,6 @@ export class AmplitudeSessionPlugin extends EventPlugin {
8171
}
8272

8373
this.lastEventTime = Date.now();
84-
console.log('execute saveSessionData');
85-
8674
await this.saveSessionData();
8775
return result;
8876
}
@@ -93,13 +81,10 @@ export class AmplitudeSessionPlugin extends EventPlugin {
9381

9482
track(event: TrackEventType) {
9583
const eventName = event.event;
96-
console.log('event',eventName);
9784

9885
if (eventName === AMP_SESSION_START_EVENT) {
99-
console.log('track Session_Start');
10086
this.resetPending = false;
10187
this.eventSessionId = this.sessionId;
102-
console.log(`[AmplitudeSession] NewSession = ${this.eventSessionId}`);
10388
}
10489

10590
if (eventName === AMP_SESSION_END_EVENT) {
@@ -177,54 +162,6 @@ export class AmplitudeSessionPlugin extends EventPlugin {
177162
this.startNewSessionIfNecessary();
178163
};
179164

180-
// private async startNewSessionIfNecessary() {
181-
// if (this.eventSessionId === -1) {
182-
// this.eventSessionId = this.sessionId;
183-
// }
184-
185-
// if (this.resetPending) return;
186-
187-
// const current = Date.now();
188-
// const withinSessionLimit = this.withinMinSessionTime(current);
189-
// console.log('withinSessionLimit', withinSessionLimit);
190-
// const isSessionExpired = this.sessionId === -1 || this.lastEventTime === -1 || !withinSessionLimit;
191-
// console.log('isSessionExpired', isSessionExpired);
192-
193-
// if (this.sessionId >= 0 && !isSessionExpired) {
194-
// this.lastEventTime = current;
195-
// await this.saveSessionData();
196-
// return; // same session, nothing to do
197-
// }
198-
// const oldSessionId = this.sessionId;
199-
// await this.endSession(oldSessionId);
200-
// this.lastEventTime = current;
201-
// await this.saveSessionData();
202-
203-
204-
// await this.startNewSession();
205-
// }
206-
207-
// private async startNewSession() {
208-
// if (this.resetPending) return;
209-
210-
// this.resetPending = true;
211-
// this.sessionId = Date.now();
212-
213-
// if (this.eventSessionId === -1) {
214-
// this.eventSessionId = this.sessionId;
215-
// }
216-
217-
// this.lastEventTime = this.sessionId;
218-
// await this.saveSessionData();
219-
220-
// console.log(`[AmplitudeSession] startNewSession -> ${this.sessionId}`);
221-
// this.analytics?.track(AMP_SESSION_START_EVENT, {
222-
// integrations: {
223-
// [this.key]: { session_id: this.sessionId },
224-
// },
225-
// });
226-
// }
227-
228165
private async startNewSessionIfNecessary() {
229166
if (this.eventSessionId === -1) {
230167
this.eventSessionId = this.sessionId;
@@ -234,14 +171,12 @@ export class AmplitudeSessionPlugin extends EventPlugin {
234171

235172
const current = Date.now();
236173
const withinSessionLimit = this.withinMinSessionTime(current);
237-
console.log('withinSessionLimit', withinSessionLimit);
238174

239175
const isSessionExpired =
240176
this.sessionId === -1 ||
241177
this.lastEventTime === -1 ||
242178
!withinSessionLimit;
243179

244-
console.log('isSessionExpired', isSessionExpired);
245180
this.lastEventTime = current;
246181

247182
if (this.sessionId >= 0 && !isSessionExpired) {
@@ -280,7 +215,6 @@ private async startNewSession() {
280215

281216
await this.trackSessionStart(newSessionId);
282217

283-
//this.resetPending = false;
284218
}
285219

286220
/**

0 commit comments

Comments
 (0)