MCPcopy Index your code
hub / github.com/linuxfoundation/crowd.dev / track

Function track

backend/src/segment/telemetryTrack.ts:10–60  ·  view source on GitHub ↗
(
  event,
  properties,
  options: any,
  userId: any = false,
  timestamp: any = false,
)

Source from the content-addressed store, hash-verified

8const log = getServiceChildLogger('telemetryTrack')
9
10export default function track(
11 event,
12 properties,
13 options: any,
14 userId: any = false,
15 timestamp: any = false,
16) {
17 const email = SequelizeRepository.getCurrentUser({
18 ...options,
19 }).email
20 if (
21 !IS_TEST_ENV &&
22 SEGMENT_CONFIG.writeKey &&
23 // This is only for events in the self-hosted version. Hosted has more telemetry.
24 API_CONFIG.edition === Edition.COMMUNITY &&
25 !email.includes('crowd.dev')
26 ) {
27 if (
28 properties &&
29 properties?.platform &&
30 properties?.platform === CROWD_ANALYTICS_PLATORM_NAME
31 ) {
32 // no need to track crowd analytics events in segment
33 // and this is also to ensure we don't get into an infinite loop
34 return
35 }
36 const Analytics = require('analytics-node')
37 const analytics = new Analytics(SEGMENT_CONFIG.writeKey)
38
39 const { userIdOut, tenantIdOut } = getTenatUser(userId, options)
40
41 const payload = {
42 userId: userIdOut,
43 event,
44 properties,
45 context: {
46 groupId: tenantIdOut,
47 },
48 ...(timestamp && { timestamp }),
49 }
50
51 try {
52 if (event === 'Conversation created') {
53 log.trace('Added conversation')
54 }
55 analytics.track(payload)
56 } catch (error) {
57 log.error(error, { payload }, 'ERROR: Could not send the following payload to Segment')
58 }
59 }
60}

Callers 15

juneIntegrationsInitFunction · 0.85
updateMethod · 0.85
updateMethod · 0.85
trackEventMethod · 0.85
trackPostClickedMethod · 0.85
createMethod · 0.85
destroyMethod · 0.85
createOrUpdateMethod · 0.85
signupMethod · 0.85
signinMethod · 0.85
signinFromSocialMethod · 0.85

Calls 4

getTenatUserFunction · 0.85
getCurrentUserMethod · 0.80
trackMethod · 0.80
errorMethod · 0.45

Tested by

no test coverage detected