Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes the properties for Mixpanel Actions #5

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,101 @@ describe('Mixpanel.identifyUser', () => {
)
})

it('name should automatically be derived from the firstName and lastName traits if they are defined.', async () => {
const event = createTestEvent({
timestamp, traits: {
firstName: 'Joe',
lastName: 'Doe'
}
})

const event2 = createTestEvent({
timestamp, traits: {
firstName: 'Joe'
}
})

const event3 = createTestEvent({
timestamp, traits: {
lastName: 'Doe'
}
})

nock('https://api.mixpanel.com').post('/engage').reply(200, {})
nock('https://api.mixpanel.com').post('/track').reply(200, {})

const responses = await testDestination.testAction('identifyUser', {
event,
useDefaultMappings: true,
settings: {
projectToken: MIXPANEL_PROJECT_TOKEN,
apiSecret: MIXPANEL_API_SECRET,
apiRegion: ApiRegions.US
}
})
expect(responses[1].options.body).toMatchObject(
new URLSearchParams({
data: JSON.stringify({
$token: MIXPANEL_PROJECT_TOKEN,
$distinct_id: 'user1234',
$ip: '8.8.8.8',
$set: {
$first_name: 'Joe',
$last_name: 'Doe',
$name: 'Joe Doe'
}
})
})
)
nock('https://api.mixpanel.com').post('/engage').reply(200, {})
nock('https://api.mixpanel.com').post('/track').reply(200, {})
const responses2 = await testDestination.testAction('identifyUser', {
event: event2,
useDefaultMappings: true,
settings: {
projectToken: MIXPANEL_PROJECT_TOKEN,
apiSecret: MIXPANEL_API_SECRET,
apiRegion: ApiRegions.US
}
})
expect(responses2[1].options.body).toMatchObject(
new URLSearchParams({
data: JSON.stringify({
$token: MIXPANEL_PROJECT_TOKEN,
$distinct_id: 'user1234',
$ip: '8.8.8.8',
$set: {
$first_name: 'Joe'
}
})
})
)
nock('https://api.mixpanel.com').post('/engage').reply(200, {})
nock('https://api.mixpanel.com').post('/track').reply(200, {})
const responses3 = await testDestination.testAction('identifyUser', {
event: event3,
useDefaultMappings: true,
settings: {
projectToken: MIXPANEL_PROJECT_TOKEN,
apiSecret: MIXPANEL_API_SECRET,
apiRegion: ApiRegions.US
}
})
expect(responses3[1].options.body).toMatchObject(
new URLSearchParams({
data: JSON.stringify({
$token: MIXPANEL_PROJECT_TOKEN,
$distinct_id: 'user1234',
$ip: '8.8.8.8',
$set: {
$last_name: 'Doe'
}
})
})
)

})

it('should use EU server URL', async () => {
const event = createTestEvent({ timestamp, traits: { abc: '123' } })

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { ActionDefinition, IntegrationError, omit } from '@segment/actions-core'
import type { Settings } from '../generated-types'
import type { Payload } from './generated-types'

import { getApiServerUrl } from '../utils'
import { getApiServerUrl, getConcatenatedName } from '../utils'

const action: ActionDefinition<Settings, Payload> = {
title: 'Identify User',
Expand Down Expand Up @@ -73,14 +73,19 @@ const action: ActionDefinition<Settings, Payload> = {
}

if (payload.traits && Object.keys(payload.traits).length > 0) {
const concatenatedName = getConcatenatedName(
payload.traits.firstName,
payload.traits.lastName,
payload.traits.name
)
const traits = {
...omit(payload.traits, ['created', 'email', 'firstName', 'lastName', 'name', 'username', 'phone']),
// to fit the Mixpanel expectations, transform the special traits to Mixpanel reserved property
$created: payload.traits.created,
$email: payload.traits.email,
$first_name: payload.traits.firstName,
$last_name: payload.traits.lastName,
$name: payload.traits.name,
$name: concatenatedName,
$username: payload.traits.username,
$phone: payload.traits.phone
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@ export const eventProperties: Record<string, InputField> = {
time: {
label: 'Timestamp',
type: 'datetime',
required: false,
description:
'The timestamp of the event. If time is not sent with the event, it will be set to the time our servers receive it.',
'The timestamp of the event. Mixpanel expects epoch timestamp in millisecond or second. Please note, Mixpanel only accepts this field as the timestamp. If the field is empty, it will be set to the time Mixpanel servers receive it.',
default: {
'@path': '$.timestamp'
}
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading