Skip to content

Commit

Permalink
add version tracking
Browse files Browse the repository at this point in the history
  • Loading branch information
ritch committed Sep 24, 2024
1 parent 65cfa91 commit 75e8e87
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
14 changes: 14 additions & 0 deletions app/packages/analytics/src/analytics.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -195,4 +195,18 @@ describe("Analytics", () => {
const redacted4 = analytics.redact(undefined);
expect(redacted4).toEqual(undefined);
});

it("should allow setting version", () => {
analytics.load({
writeKey: "test",
userId: "user",
userGroup: "group",
debug: false,
version: "1.0.0",
});
analytics.track("custom_event");
expect(mockSegment.track).toHaveBeenCalledWith("custom_event", undefined, {
version: "1.0.0",
});
});
});
8 changes: 8 additions & 0 deletions app/packages/analytics/src/usingAnalytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export type AnalyticsInfo = {
debug: boolean;
disableUrlTracking?: boolean;
redact?: string[];
version?: string;
};

export type AnalyticsConfig = {
Expand All @@ -33,6 +34,7 @@ export class Analytics {
private _debounceInterval = 1000; // Default debounce interval in milliseconds (5 seconds)
private _disableUrlTracking = false;
private _redactedProperties: string[] = [];
private _version?: string;

constructor(config?: AnalyticsConfig) {
if (config?.debounceInterval) {
Expand Down Expand Up @@ -75,6 +77,9 @@ export class Analytics {
this._segment = AnalyticsBrowser.load({
writeKey: info.writeKey,
});
if (info.version) {
this._version = info.version;
}
if (info.userId) {
this.identify(info.userId);
}
Expand Down Expand Up @@ -116,6 +121,9 @@ export class Analytics {
if (this._disableUrlTracking) {
opts = { context: { page: { url: undefined } } };
}
if (this._version) {
opts = { ...opts, version: this._version };
}
this._segment.track(name, properties, opts);
}

Expand Down

0 comments on commit 75e8e87

Please sign in to comment.