Skip to content

Commit

Permalink
chore: segment init change
Browse files Browse the repository at this point in the history
  • Loading branch information
hetunandu committed Dec 17, 2024
1 parent 2549d3c commit a9c3d68
Showing 1 changed file with 6 additions and 16 deletions.
22 changes: 6 additions & 16 deletions app/client/src/utils/Analytics/segment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,12 @@ class SegmentSingleton {
}

public async init(): Promise<boolean> {
const { segment } = getAppsmithConfigs();

if (!segment.enabled) {
return true;
}

if (this.analytics) {
log.warn("Segment is already initialized.");

Expand Down Expand Up @@ -86,40 +92,24 @@ class SegmentSingleton {
public track(eventName: string, eventData: EventProperties) {
if (this.analytics) {
this.analytics.track(eventName, eventData);
} else {
log.warn("Segment is not initialized.");
}
}

public async identify(userId: string, traits: UserTraits) {
if (this.analytics) {
await this.analytics.identify(userId, traits);
} else {
log.warn("Segment is not initialized.");
}
}

public async addMiddleware(middleware: MiddlewareFunction) {
if (this.analytics) {
await this.analytics.addSourceMiddleware(middleware);
} else {
log.warn("Segment is not initialized.");
}
}

public page(name?: string, properties?: EventProperties) {
if (this.analytics) {
this.analytics.page(name, properties);
} else {
log.warn("Segment is not initialized.");
}
}

public reset() {
if (this.analytics) {
this.analytics.reset();
} else {
log.warn("Segment is not initialized.");
}
}
}
Expand Down

0 comments on commit a9c3d68

Please sign in to comment.