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

fix: Mixpanel Transformer - Fall Back to message.context.traits for Group Key Retrieval #4053

Open
wants to merge 1 commit into
base: develop
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
6 changes: 4 additions & 2 deletions src/v0/destinations/mp/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -369,13 +369,15 @@ const processAliasEvents = (message, type, destination) => {
const processGroupEvents = (message, type, destination) => {
const returnValue = [];
const groupKeys = getValuesAsArrayFromConfig(destination.Config.groupKeySettings, 'groupKey');
const traits =
Object.keys(message.traits ?? {}).length > 0 ? message.traits : message.context.traits ?? {};
let groupKeyVal;
if (groupKeys.length > 0) {
groupKeys.forEach((groupKey) => {
groupKeyVal =
groupKey === 'groupId'
? getFieldValueFromMessage(message, 'groupId')
: get(message.traits, groupKey);
: get(traits, groupKey);
if (groupKeyVal && !Array.isArray(groupKeyVal)) {
groupKeyVal = [groupKeyVal];
}
Expand All @@ -399,7 +401,7 @@ const processGroupEvents = (message, type, destination) => {
$group_key: groupKey,
$group_id: value,
$set: {
...message.traits,
...traits,
},
};
const groupResponse = responseBuilderSimple(
Expand Down
240 changes: 240 additions & 0 deletions test/integrations/destinations/mp/processor/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6190,4 +6190,244 @@ export const data = [
},
},
},
{
name: 'mp',
description: 'Test fallback for traits to context traits on group call',
feature: 'processor',
module: 'destination',
version: 'v0',
input: {
request: {
body: [
{
destination: overrideDestination(sampleDestination, {
groupKeySettings: [{ groupKey: 'company' }],
}),
message: {
anonymousId: 'e6ab2c5e-2cda-44a9-a962-e2f67df78bca',
channel: 'mobile',
name: 'Contact Us',
context: {
app: {
build: '1.0.0',
name: 'RudderLabs Android SDK',
namespace: 'com.rudderlabs.javascript',
version: '1.0.5',
},
ip: '0.0.0.0',
library: { name: 'RudderLabs JavaScript SDK', version: '1.0.5' },
locale: 'en-GB',
os: { name: '', version: '' },
screen: { density: 2 },
traits: { company: 'testComp' },
userAgent:
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.117 Safari/537.36',
},
integrations: { All: true },
messageId: 'dd266c67-9199-4a52-ba32-f46ddde67312',
originalTimestamp: '2020-01-24T06:29:02.358Z',
properties: {
path: '/tests/html/index2.html',
referrer: '',
search: '',
title: '',
url: 'http://localhost/tests/html/index2.html',
},
traits: {},
receivedAt: '2020-01-24T11:59:02.403+05:30',
request_ip: '[::1]:53708',
sentAt: '2020-01-24T06:29:02.359Z',
timestamp: '2020-01-24T11:59:02.402+05:30',
type: 'group',
userId: 'hjikl',
},
},
],
method: 'POST',
},
pathSuffix: '',
},
output: {
response: {
status: 200,
body: [
{
output: {
version: '1',
type: 'REST',
method: 'POST',
endpoint: 'https://api.mixpanel.com/engage/',
headers: {},
params: {},
body: {
JSON: {},
JSON_ARRAY: {
batch:
'[{"$token":"test_api_token","$distinct_id":"hjikl","$set":{"company":["testComp"]},"$ip":"0.0.0.0"}]',
},
XML: {},
FORM: {},
},
files: {},
userId: 'hjikl',
},
statusCode: 200,
},
{
output: {
version: '1',
type: 'REST',
method: 'POST',
endpoint: 'https://api.mixpanel.com/groups/',
headers: {},
params: {},
body: {
JSON: {},
JSON_ARRAY: {
batch:
'[{"$token":"test_api_token","$group_key":"company","$group_id":"testComp","$set":{"company":"testComp"}}]',
},
XML: {},
FORM: {},
},
files: {},
userId: 'hjikl',
},
statusCode: 200,
},
],
},
},
},
{
name: 'mp',
description: 'Test fallback to traits for when groupId is an array',
feature: 'processor',
module: 'destination',
version: 'v0',
input: {
request: {
body: [
{
destination: overrideDestination(sampleDestination, {
groupKeySettings: [{ groupKey: 'company' }],
}),
message: {
anonymousId: 'e6ab2c5e-2cda-44a9-a962-e2f67df78bca',
channel: 'mobile',
name: 'Contact Us',
context: {
app: {
build: '1.0.0',
name: 'RudderLabs Android SDK',
namespace: 'com.rudderlabs.javascript',
version: '1.0.5',
},
ip: '0.0.0.0',
library: { name: 'RudderLabs JavaScript SDK', version: '1.0.5' },
locale: 'en-GB',
os: { name: '', version: '' },
screen: { density: 2 },
traits: { company: ['testComp', 'testComp1'] },
userAgent:
'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.117 Safari/537.36',
},
integrations: { All: true },
messageId: 'dd266c67-9199-4a52-ba32-f46ddde67312',
originalTimestamp: '2020-01-24T06:29:02.358Z',
properties: {
path: '/tests/html/index2.html',
referrer: '',
search: '',
title: '',
url: 'http://localhost/tests/html/index2.html',
},
traits: {},
receivedAt: '2020-01-24T11:59:02.403+05:30',
request_ip: '[::1]:53708',
sentAt: '2020-01-24T06:29:02.359Z',
timestamp: '2020-01-24T11:59:02.402+05:30',
type: 'group',
userId: 'hjikl',
},
},
],
method: 'POST',
},
pathSuffix: '',
},
output: {
response: {
status: 200,
body: [
{
output: {
version: '1',
type: 'REST',
method: 'POST',
endpoint: 'https://api.mixpanel.com/engage/',
headers: {},
params: {},
body: {
JSON: {},
JSON_ARRAY: {
batch:
'[{"$token":"test_api_token","$distinct_id":"hjikl","$set":{"company":["testComp","testComp1"]},"$ip":"0.0.0.0"}]',
},
XML: {},
FORM: {},
},
files: {},
userId: 'hjikl',
},
statusCode: 200,
},
{
output: {
version: '1',
type: 'REST',
method: 'POST',
endpoint: 'https://api.mixpanel.com/groups/',
headers: {},
params: {},
body: {
JSON: {},
JSON_ARRAY: {
batch:
'[{"$token":"test_api_token","$group_key":"company","$group_id":"testComp","$set":{"company":["testComp","testComp1"]}}]',
},
XML: {},
FORM: {},
},
files: {},
userId: 'hjikl',
},
statusCode: 200,
},
{
output: {
version: '1',
type: 'REST',
method: 'POST',
endpoint: 'https://api.mixpanel.com/groups/',
headers: {},
params: {},
body: {
JSON: {},
JSON_ARRAY: {
batch:
'[{"$token":"test_api_token","$group_key":"company","$group_id":"testComp1","$set":{"company":["testComp","testComp1"]}}]',
},
XML: {},
FORM: {},
},
files: {},
userId: 'hjikl',
},
statusCode: 200,
},
],
},
},
},
];