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