Skip to content
Closed
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
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -114,5 +114,6 @@
},
"dependencies": {
"chance": "^1.1.8"
}
},
"packageManager": "yarn@1.22.19+sha512.ff4579ab459bb25aa7c0ff75b62acebe576f6084b36aa842971cf250a5d8c6cd3bc9420b22ce63c7f93a0857bc6ef29291db39c3e7a23aab5adfd5a4dd6c5d71"
}
Original file line number Diff line number Diff line change
Expand Up @@ -806,4 +806,36 @@ describe('Set Configuration Fields action', () => {
send_page_view: false
})
})

it('should convert consent values to lower case', async () => {
defaultSettings.enableConsentMode = true

const [setConfigurationEventPlugin] = await googleAnalytics4Web({
...defaultSettings,
subscriptions
})
setConfigurationEvent = setConfigurationEventPlugin
await setConfigurationEventPlugin.load(Context.system(), {} as Analytics)

const context = new Context({
event: 'setConfigurationFields',
type: 'page',
properties: {
ads_storage_consent_state: 'GRANTED',
analytics_storage_consent_state: 'Granted'
}
})

setConfigurationEvent.page?.(context)

expect(mockGtag).toHaveBeenCalledWith('consent', 'update', {
ad_storage: 'granted',
analytics_storage: 'granted'
})
expect(mockGtag).toHaveBeenCalledWith('config', 'G-XXXXXXXXXX', {
allow_ad_personalization_signals: false,
allow_google_signals: false,
send_page_view: true
})
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,23 @@ const action: BrowserActionDefinition<Settings, Function, Payload> = {
description:
'Consent state indicated by the user for ad cookies. Value must be “granted” or “denied.” This is only used if the Enable Consent Mode setting is on.',
label: 'Ads Storage Consent State',
type: 'string'
type: 'string',
choices: [
{ label: 'Granted', value: 'granted' },
{ label: 'Denied', value: 'denied' }
],
default: undefined
},
analytics_storage_consent_state: {
description:
'Consent state indicated by the user for ad cookies. Value must be “granted” or “denied.” This is only used if the Enable Consent Mode setting is on.',
label: 'Analytics Storage Consent State',
type: 'string'
type: 'string',
choices: [
{ label: 'Granted', value: 'granted' },
{ label: 'Denied', value: 'denied' }
],
default: undefined
},
ad_user_data_consent_state: {
description:
Expand Down Expand Up @@ -140,10 +150,10 @@ const action: BrowserActionDefinition<Settings, Function, Payload> = {
ad_personalization?: ConsentParamsArg
} = {}
if (payload.ads_storage_consent_state) {
consentParams.ad_storage = payload.ads_storage_consent_state as ConsentParamsArg
consentParams.ad_storage = payload.ads_storage_consent_state.toLowerCase() as ConsentParamsArg
}
if (payload.analytics_storage_consent_state) {
consentParams.analytics_storage = payload.analytics_storage_consent_state as ConsentParamsArg
consentParams.analytics_storage = payload.analytics_storage_consent_state.toLowerCase() as ConsentParamsArg
}
if (payload.ad_user_data_consent_state) {
consentParams.ad_user_data = payload.ad_user_data_consent_state as ConsentParamsArg
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,4 +204,52 @@ describe('Hubspot.upsertContact', () => {
}
])
})

test('trims string traits', async () => {
const context = new Context({
type: 'identify',
userId: 'mike',
traits: {
friendly: false,
email: 'mike_eh@lph.com',
address: {
street: '6th St',
city: ' San Francisco ', // to be trimmed
state: 'CA',
postalCode: '94103',
country: 'USA'
},
equipment: {
type: '🚘',
color: ' red ', // to be trimmed
make: {
make: 'Tesla',
model: 'Model S',
year: 2019
}
}
}
})

await upsertContactEvent.identify?.(context)
expect(mockHubspot.push).toHaveBeenCalledTimes(1)
expect(mockHubspot.push).toHaveBeenCalledWith([
'identify',
{
email: 'mike_eh@lph.com',
id: 'mike',
friendly: false,
address: '6th St',
country: 'USA',
state: 'CA',
city: 'San Francisco',
zip: '94103',
equipment_type: '🚘',
equipment_color: 'red',
equipment_make_make: 'Tesla',
equipment_make_model: 'Model S',
equipment_make_year: 2019
}
])
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ const action: BrowserActionDefinition<Settings, Hubspot, Payload> = {
}
},
custom_properties: {
description: 'A list of key-value pairs that describe the contact. Please see [HubSpot`s documentation](https://knowledge.hubspot.com/account/prevent-contact-properties-update-through-tracking-code-api) for limitations in updating contact properties.',
description:
'A list of key-value pairs that describe the contact. Please see [HubSpot`s documentation](https://knowledge.hubspot.com/account/prevent-contact-properties-update-through-tracking-code-api) for limitations in updating contact properties.',
label: 'Custom Properties',
type: 'object',
required: false,
Expand Down Expand Up @@ -103,6 +104,15 @@ const action: BrowserActionDefinition<Settings, Hubspot, Payload> = {
return
}

payload.email = payload.email?.trim()
payload.id = payload.id?.trim()
payload.company = payload.company?.trim()
payload.country = payload.country?.trim()
payload.state = payload.state?.trim()
payload.city = payload.city?.trim()
payload.address = payload.address?.trim()
payload.zip = payload.zip?.trim()

// custom properties should be key-value pairs of strings, therefore, filtering out any non-primitive
const { custom_properties, ...rest } = payload
let flattenProperties
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ export function flatten(
const flattened = flatten(data[key] as Properties, `${prefix}_${key}`, skipList, keyTransformation)
result = { ...result, ...flattened }
} else {
result[keyTransformation(`${prefix}_${key}`.replace(/^_/, ''))] = data[key] as JSONPrimitive
result[keyTransformation(`${prefix}_${key}`.replace(/^_/, ''))] = (
typeof data[key] === 'string' ? (data[key] as string).trim() : data[key]
) as JSONPrimitive
}
}
return result
Expand Down
2 changes: 1 addition & 1 deletion packages/destination-actions/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@segment/action-destinations",
"description": "Destination Actions engine and definitions.",
"version": "3.345.0",
"version": "3.345.1",
"repository": {
"type": "git",
"url": "https://github.com/segmentio/action-destinations",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,32 @@

exports[`Testing snapshot for drip destination: identify action - all fields 1`] = `
Object {
"custom_fields": Object {
"testType": "XoS!vJs",
},
"email": "mivsaj@pu.co.uk",
"ip_address": "33.172.51.152",
"sms_number": "XoS!vJs",
"status": "XoS!vJs",
"status_updated_at": "2021-02-01T00:00:00.000Z",
"tags": Array [
"XoS!vJs",
"subscribers": Array [
Object {
"custom_fields": Object {
"testType": "XoS!vJs",
},
"email": "mivsaj@pu.co.uk",
"ip_address": "33.172.51.152",
"sms_number": "XoS!vJs",
"status": "XoS!vJs",
"status_updated_at": "2021-02-01T00:00:00.000Z",
"tags": Array [
"XoS!vJs",
],
"time_zone": "XoS!vJs",
},
],
"time_zone": "XoS!vJs",
}
`;

exports[`Testing snapshot for drip destination: identify action - required fields 1`] = `
Object {
"email": "mivsaj@pu.co.uk",
"subscribers": Array [
Object {
"email": "mivsaj@pu.co.uk",
},
],
}
`;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,31 @@

exports[`Testing snapshot for Drip's identify destination action: all fields 1`] = `
Object {
"custom_fields": Object {
"testType": "DVw6A7$UK[I",
},
"email": "okavno@kulusof.bg",
"ip_address": "100.102.165.77",
"sms_number": "DVw6A7$UK[I",
"status": "DVw6A7$UK[I",
"status_updated_at": "2021-02-01T00:00:00.000Z",
"tags": Array [
"DVw6A7$UK[I",
"subscribers": Array [
Object {
"custom_fields": Object {
"testType": "DVw6A7$UK[I",
},
"email": "okavno@kulusof.bg",
"ip_address": "100.102.165.77",
"sms_number": "DVw6A7$UK[I",
"status": "DVw6A7$UK[I",
"status_updated_at": "2021-02-01T00:00:00.000Z",
"tags": Array [
"DVw6A7$UK[I",
],
"time_zone": "DVw6A7$UK[I",
},
],
"time_zone": "DVw6A7$UK[I",
}
`;

exports[`Testing snapshot for Drip's identify destination action: required fields 1`] = `
Object {
"email": "okavno@kulusof.bg",
"subscribers": Array [
Object {
"email": "okavno@kulusof.bg",
},
],
}
`;
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,15 @@ describe('Drip.identify', () => {
phone: '1234567890',
status: 'unsubscribed',
status_updated_at: '2021-01-01T00:00:00Z',
custom_fields: { fizz: 'buzz', numb:1234, bool:true, oppBool:false, arr: ["hello", 1234, false], obj: { key: 'value' }, null: null },
custom_fields: {
fizz: 'buzz',
numb: 1234,
bool: true,
oppBool: false,
arr: ['hello', 1234, false],
obj: { key: 'value' },
null: null
},
tags: 'tag1,tag2'
}
})
Expand All @@ -36,14 +44,25 @@ describe('Drip.identify', () => {
})

const body = {
custom_fields: { fizz: 'buzz', numb:"1234", bool:"true", oppBool:"false", arr: "[\"hello\",1234,false]", obj: "{\"key\":\"value\"}" },
email: 'test@example.com',
ip_address: '127.0.0.1',
sms_number: '1234567890',
status: 'unsubscribed',
status_updated_at: '2021-01-01T00:00:00Z',
tags: ['tag1', 'tag2'],
time_zone: 'Europe/Amsterdam'
subscribers: [
{
custom_fields: {
fizz: 'buzz',
numb: '1234',
bool: 'true',
oppBool: 'false',
arr: '["hello",1234,false]',
obj: '{"key":"value"}'
},
email: 'test@example.com',
ip_address: '127.0.0.1',
sms_number: '1234567890',
status: 'unsubscribed',
status_updated_at: '2021-01-01T00:00:00Z',
tags: ['tag1', 'tag2'],
time_zone: 'Europe/Amsterdam'
}
]
}

expect(responses.length).toBe(1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const person = (payload: Payload) => {
.map(([key, value]) => [key, typeof value === 'object' ? JSON.stringify(value) : String(value)])
)
return Object.keys(result).length > 0 ? result : undefined
})(),
})(),
email: payload.email,
ip_address: payload.ip,
sms_number: payload.phone,
Expand Down Expand Up @@ -95,7 +95,7 @@ const action: ActionDefinition<Settings, Payload> = {
perform: (request, { settings, payload }) => {
return request(`https://api.getdrip.com/v2/${settings.accountId}/subscribers`, {
method: 'POST',
json: person(payload)
json: { subscribers: [person(payload)] }
})
},
performBatch: (request, { settings, payload }) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const destination: DestinationDefinition<Settings> = {
name: 'Drip (Actions)',
slug: 'actions-drip',
mode: 'cloud',
description: 'Send Segment events to Drip',
description: 'Send Segment analytics events and user profile details to Drip',
authentication: {
scheme: 'custom',
fields: {
Expand Down
Loading
Loading