Skip to content

Commit

Permalink
Update AppFit destination with new structure (segmentio#2124)
Browse files Browse the repository at this point in the history
We needed to send a few other fields from the context to make our app
more robust.
  • Loading branch information
claude authored Jul 9, 2024
1 parent 3af99ed commit 781959c
Show file tree
Hide file tree
Showing 5 changed files with 145 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,27 @@ Object {
"occurredAt": "2021-02-01T00:00:00.000Z",
"payload": Object {
"anonymousId": "m]^ldlwPRQruDQ&OXR1",
"deviceId": "m]^ldlwPRQruDQ&OXR1",
"deviceType": "m]^ldlwPRQruDQ&OXR1",
"eventId": "m]^ldlwPRQruDQ&OXR1",
"name": "m]^ldlwPRQruDQ&OXR1",
"osName": "m]^ldlwPRQruDQ&OXR1",
"eventName": "m]^ldlwPRQruDQ&OXR1",
"properties": Object {
"testType": "m]^ldlwPRQruDQ&OXR1",
},
"sourceEventId": "m]^ldlwPRQruDQ&OXR1",
"systemProperties": Object {
"appVersion": "m]^ldlwPRQruDQ&OXR1",
"device": Object {
"advertisingId": "m]^ldlwPRQruDQ&OXR1",
"id": "m]^ldlwPRQruDQ&OXR1",
"manufacturer": "m]^ldlwPRQruDQ&OXR1",
"model": "m]^ldlwPRQruDQ&OXR1",
},
"ipAddress": "m]^ldlwPRQruDQ&OXR1",
"os": Object {
"name": "m]^ldlwPRQruDQ&OXR1",
"version": "m]^ldlwPRQruDQ&OXR1",
},
},
"userId": "m]^ldlwPRQruDQ&OXR1",
"version": "2",
},
}
`;
Expand All @@ -24,8 +36,13 @@ Object {
"eventSource": "segment",
"occurredAt": "2021-02-01T00:00:00.000Z",
"payload": Object {
"eventId": "m]^ldlwPRQruDQ&OXR1",
"name": "m]^ldlwPRQruDQ&OXR1",
"eventName": "m]^ldlwPRQruDQ&OXR1",
"sourceEventId": "m]^ldlwPRQruDQ&OXR1",
"systemProperties": Object {
"device": Object {},
"os": Object {},
},
"version": "2",
},
}
`;
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,27 @@ Object {
"occurredAt": "2021-02-01T00:00:00.000Z",
"payload": Object {
"anonymousId": "M$xwt#p",
"deviceId": "M$xwt#p",
"deviceType": "M$xwt#p",
"eventId": "M$xwt#p",
"name": "M$xwt#p",
"osName": "M$xwt#p",
"eventName": "M$xwt#p",
"properties": Object {
"testType": "M$xwt#p",
},
"sourceEventId": "M$xwt#p",
"systemProperties": Object {
"appVersion": "M$xwt#p",
"device": Object {
"advertisingId": "M$xwt#p",
"id": "M$xwt#p",
"manufacturer": "M$xwt#p",
"model": "M$xwt#p",
},
"ipAddress": "M$xwt#p",
"os": Object {
"name": "M$xwt#p",
"version": "M$xwt#p",
},
},
"userId": "M$xwt#p",
"version": "2",
},
}
`;
Expand All @@ -24,8 +36,13 @@ Object {
"eventSource": "segment",
"occurredAt": "2021-02-01T00:00:00.000Z",
"payload": Object {
"eventId": "M$xwt#p",
"name": "M$xwt#p",
"eventName": "M$xwt#p",
"sourceEventId": "M$xwt#p",
"systemProperties": Object {
"device": Object {},
"os": Object {},
},
"version": "2",
},
}
`;
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,16 @@ describe('AppFit.track', () => {
it('should create an event', async () => {
const timestamp = new Date().toISOString()
const event = createTestEvent({
name: 'Segment Test Event Name',
event: 'Segment Test Event Name',
messageId: '12345',
userId: 'userId1',
timestamp,
context: { device: { id: 'device1234', type: 'ios' }, os: { name: 'iPhone OS' } },
context: {
ip: '8.8.8.8',
app: { version: '1.0.0' },
device: { id: 'device1234', advertisingId: 'adId1234', type: 'ios', model: 'iPhone7,2', manufacturer: 'Apple' },
os: { name: 'iPhone OS', version: '10.1' }
},
properties: { foo: 'bar' }
})

Expand All @@ -28,7 +33,7 @@ describe('AppFit.track', () => {
expect(responses[0].status).toBe(200)
expect(responses[0].data).toMatchObject({})
expect(responses[0].options.body).toBe(
`{"eventSource":"segment","occurredAt":"${timestamp}","payload":{"eventId":"12345","userId":"userId1","anonymousId":"anonId1234","name":"Test Event","properties":{"foo":"bar"},"deviceId":"device1234","deviceType":"ios","osName":"iPhone OS"}}`
`{"eventSource":"segment","occurredAt":"${timestamp}","payload":{"version":"2","sourceEventId":"12345","eventName":"Segment Test Event Name","userId":"userId1","anonymousId":"anonId1234","properties":{"foo":"bar"},"systemProperties":{"appVersion":"1.0.0","ipAddress":"8.8.8.8","os":{"name":"iPhone OS","version":"10.1"},"device":{"id":"device1234","advertisingId":"adId1234","manufacturer":"Apple","model":"iPhone7,2"}}}}`
)
})
})

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

Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,14 @@ const action: ActionDefinition<Settings, Payload> = {
'@path': '$.properties'
}
},
appVersion: {
label: 'App Version',
description: 'The app version',
type: 'string',
default: {
'@path': '$.context.app.version'
}
},
deviceId: {
label: 'Device ID',
description: 'The device ID of the user',
Expand All @@ -65,6 +73,38 @@ const action: ActionDefinition<Settings, Payload> = {
'@path': '$.context.device.type'
}
},
deviceManufacturer: {
label: 'Device Manufacturer',
description: 'The device manufacturer',
type: 'string',
default: {
'@path': '$.context.device.manufacturer'
}
},
deviceModel: {
label: 'Device Model',
description: 'The device model',
type: 'string',
default: {
'@path': '$.context.device.model'
}
},
deviceAdvertisingId: {
label: 'Device Advertising ID',
description: 'The device advertising ID',
type: 'string',
default: {
'@path': '$.context.device.advertisingId'
}
},
ipAddress: {
label: 'IP Address',
description: 'The IP address of the client',
type: 'string',
default: {
'@path': '$.context.ip'
}
},
osName: {
label: 'OS Name',
description: 'The name of the operating system',
Expand All @@ -73,6 +113,14 @@ const action: ActionDefinition<Settings, Payload> = {
'@path': '$.context.os.name'
}
},
osVersion: {
label: 'OS Version',
description: 'The version of the operating system',
type: 'string',
default: {
'@path': '$.context.os.version'
}
},
eventId: {
label: 'Event ID',
description: 'The event ID',
Expand All @@ -92,14 +140,26 @@ const action: ActionDefinition<Settings, Payload> = {
eventSource: 'segment',
occurredAt: payload.occurredAt,
payload: {
eventId: payload.eventId,
version: '2',
sourceEventId: payload.eventId,
eventName: payload.name,
userId: payload.userId,
anonymousId: payload.anonymousId,
name: payload.name,
properties: payload.properties,
deviceId: payload.deviceId,
deviceType: payload.deviceType,
osName: payload.osName
systemProperties: {
appVersion: payload.appVersion,
ipAddress: payload.ipAddress,
os: {
name: payload.osName,
version: payload.osVersion
},
device: {
id: payload.deviceId,
advertisingId: payload.deviceAdvertisingId,
manufacturer: payload.deviceManufacturer,
model: payload.deviceModel
}
}
}
}
})
Expand Down

0 comments on commit 781959c

Please sign in to comment.