Skip to content

Commit

Permalink
feat: Added googleAnalyticsUserProperty options
Browse files Browse the repository at this point in the history
  • Loading branch information
edgardmessias committed Jun 28, 2022
1 parent 79b0c76 commit f425767
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/config.ts
Expand Up @@ -50,18 +50,32 @@ export interface Config {
*/
googleAnalyticsId: string | null;

/**
* Google Analytics Id
*/
googleAnalyticsUserProperty: {
[key: string]: string | number | boolean;
};

/**
* Link Preview API servers
*/
linkPreviewApiServers: string[] | null;

/**
* Project name for google analytics
*/
poweredBy: string | null;
}

export const defaultConfig: Config = {
deviceName: false,
liveLocationLimit: 10,
disableGoogleAnalytics: false,
googleAnalyticsId: null,
googleAnalyticsUserProperty: {},
linkPreviewApiServers: null,
poweredBy: 'WA-JS',
};

export const config: Config = defaultConfig;
Expand Down
9 changes: 9 additions & 0 deletions src/gtag/index.ts
Expand Up @@ -40,6 +40,7 @@ internalEv.on('webpack.injected', () => {
// Add version info
mainTracker.setUserProperty('method', method);
mainTracker.setUserProperty('wa_js', waVersion);
mainTracker.setUserProperty('powered_by', config.poweredBy || '-');
mainTracker.setUserProperty(
'whatsapp',
(window as any).Debug?.VERSION || '-'
Expand All @@ -50,11 +51,19 @@ internalEv.on('webpack.injected', () => {
if (otherTracker) {
otherTracker.setUserProperty('method', method);
otherTracker.setUserProperty('wa_js', waVersion);
otherTracker.setUserProperty('powered_by', config.poweredBy || '-');
otherTracker.setUserProperty(
'whatsapp',
(window as any).Debug?.VERSION || '-'
);

if (typeof config.googleAnalyticsUserProperty === 'object') {
for (const key in config.googleAnalyticsUserProperty) {
const value = config.googleAnalyticsUserProperty[key];
otherTracker.setUserProperty(key, value);
}
}

otherTracker.trackEvent('page_view', { authenticated, method });
}
});
Expand Down

0 comments on commit f425767

Please sign in to comment.