MCPcopy
hub / github.com/linuxfoundation/crowd.dev / identify

Function identify

backend/src/segment/track.ts:10–67  ·  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('segment')
9
10export default async function identify(
11 event,
12 properties,
13 options: any,
14 userId: any = false,
15 timestamp: any = false,
16) {
17 const userEmail = SequelizeRepository.getCurrentUser({
18 ...options,
19 }).email
20 if (
21 !IS_TEST_ENV &&
22 SEGMENT_CONFIG.writeKey &&
23 // This is only for events in the hosted version. Self-hosted has less telemetry.
24 (API_CONFIG.edition === Edition.CROWD_HOSTED || API_CONFIG.edition === Edition.LFX) &&
25 userEmail !== 'help@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
37 const Analytics = require('analytics-node')
38 const analytics = new Analytics(SEGMENT_CONFIG.writeKey)
39
40 const { userIdOut, tenantIdOut } = getTenatUser(userId, options)
41
42 const payload = {
43 userId: userIdOut,
44 event,
45 properties,
46 context: {
47 groupId: tenantIdOut,
48 },
49 ...(timestamp && { timestamp }),
50 }
51
52 try {
53 analytics.track(payload)
54
55 // send product analytics data to crowd tenant workspace
56 // await addProductData({
57 // userId: userIdOut,
58 // tenantId: tenantIdOut,
59 // event,
60 // timestamp,
61 // properties,
62 // })
63 } catch (error) {
64 log.error(error, { payload }, 'Could not send the following payload to Segment')
65 }
66 }
67}

Callers 4

signupMethod · 0.50
signinMethod · 0.50
signinFromSocialMethod · 0.50
signinFromSSOMethod · 0.50

Calls 4

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

Tested by

no test coverage detected