Skip to content

Commit

Permalink
enhancement: more analytics tracking data (#704)
Browse files Browse the repository at this point in the history
* misc: add rcAccountId hash for tracking

* misc: add client id for tracking
  • Loading branch information
embbnux authored Aug 31, 2023
1 parent 5ddad1b commit 0e4a15e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
22 changes: 16 additions & 6 deletions src/modules/Analytics/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ const FILTERED_EVENTS = [
];

function getHashId(id) {
if (!id) {
return null;
}
const secretKey = process.env.ANALYTICS_SECRET_KEY;
return crypto.createHash('sha256').update(
`${id}:${secretKey}`
Expand All @@ -32,6 +35,7 @@ export class Analytics extends AnalyticsBase {
protected _trackRouters: TrackRouter[];
protected _enableExternalAnalytics: boolean;
protected _segment: AnalyticsBrowser;
protected _hashedAccountId: string | null;

constructor(deps) {
super(deps);
Expand All @@ -40,6 +44,7 @@ export class Analytics extends AnalyticsBase {
}
this._trackRouters = trackRouters;
this._enableExternalAnalytics = !!deps.analyticsOptions.enableExternalAnalytics;
this._hashedAccountId = null;
}

override onInitOnce() {
Expand Down Expand Up @@ -73,12 +78,15 @@ export class Analytics extends AnalyticsBase {
userId: options.userId,
rcAccountId: hashedAccountId,
});
this.analytics?.group(hashedAccountId, {}, {
integrations: {
All: true,
Mixpanel: true,
},
});
if (options.accountId) {
this._hashedAccountId = hashedAccountId;
this.analytics?.group(hashedAccountId, {}, {
integrations: {
All: true,
Mixpanel: true,
},
});
}
}

track(event, properties = {}) {
Expand Down Expand Up @@ -160,6 +168,8 @@ export class Analytics extends AnalyticsBase {
brand: this._deps.brand.defaultConfig.code,
osPlatform: navigator.platform,
externalAppName: this._deps.analyticsOptions.externalAppName,
externalClientId: this._deps.analyticsOptions.externalClientId,
rcAccountId: this._hashedAccountId,
};
}

Expand Down
1 change: 1 addition & 0 deletions src/modules/Phone/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -783,6 +783,7 @@ export function createPhone({
analyticsKey: process.env.SEGMENT_KEY,
analyticsSecretKey: process.env.ANALYTICS_SECRET_KEY,
externalAppName: userAgent ? userAgent.split('/')[0] : undefined,
externalClientId: apiConfig.clientId,
},
},
{
Expand Down

0 comments on commit 0e4a15e

Please sign in to comment.