Skip to content

Commit f6ddce1

Browse files
committed
fix(analytics): improve ga and init clarity
1 parent 5178bfc commit f6ddce1

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

frontend/src/models/auth.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import cloudController from '../services/cloudController'
33
import Controller, { emit } from '../services/Controller'
44
import network from '../services/Network'
55
import browser from '../services/browser'
6+
import analytics from '../services/analytics'
67
import { selectDeviceModelAttributes } from '../selectors/devices'
78
import {
89
CLIENT_ID,
@@ -225,6 +226,7 @@ export default createModel<RootModel>()({
225226
async signedIn(_: void, state) {
226227
dispatch.ui.init()
227228
zendesk.initChat(state.auth.user)
229+
analytics.signedIn(state.auth.user)
228230
cloudController.init()
229231
cloudSync.init()
230232
network.tick()

frontend/src/services/analytics.ts

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
import browser from './browser'
1+
import browser, { getOs, getApp } from './browser'
22
import {
33
GOOGLE_TAG_MANAGER_DESKTOP_KEY,
44
GOOGLE_TAG_MANAGER_PORTAL_KEY,
55
GOOGLE_TAG_MANAGER_ANDROID_KEY,
66
GOOGLE_TAG_MANAGER_IOS_KEY,
77
} from '../constants'
88
import TagManager from 'react-gtm-module'
9+
import { version } from '../helpers/versionHelper'
910

1011
const analytics = {
1112
initialize() {
@@ -18,13 +19,21 @@ const analytics = {
1819
: GOOGLE_TAG_MANAGER_DESKTOP_KEY
1920
console.log('ANALYTICS INITIALIZE')
2021
TagManager.initialize({ gtmId: gtmId?.trim() })
21-
// analytics.initializeClarity()
22+
TagManager.dataLayer({
23+
dataLayer: {
24+
app_version: version,
25+
platform: getOs(),
26+
app_name: getApp(),
27+
},
28+
})
2229
},
2330

24-
// initializeClarity() {
25-
// const user = store.getState().user
26-
// if (window.clarity) window.clarity('set', 'user', user.email)
27-
// },
31+
signedIn(user?: IUser) {
32+
if (user) {
33+
TagManager.dataLayer({ dataLayer: { user_id: user.id } })
34+
if (window.clarity) window.clarity('identify', user.id)
35+
}
36+
},
2837
}
2938

3039
export default analytics

0 commit comments

Comments
 (0)