( event, properties, options: any, userId: any = false, timestamp: any = false, )
| 8 | const log = getServiceChildLogger('telemetryTrack') |
| 9 | |
| 10 | export 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 | |
| 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 | } |
no test coverage detected