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

feat: amplitude add support for unset #2941

Merged
merged 10 commits into from
Dec 26, 2023
13 changes: 12 additions & 1 deletion src/v0/destinations/am/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,15 @@ const identifyBuilder = (message, destination, rawPayload) => {
}
});
}
// update identify call request with unset fields
const fieldsToUnset = get(message, 'integrations.Amplitude.fieldsToUnset');
koladilip marked this conversation as resolved.
Show resolved Hide resolved
koladilip marked this conversation as resolved.
Show resolved Hide resolved
koladilip marked this conversation as resolved.
Show resolved Hide resolved
if (fieldsToUnset) {
const unsetObject = Object.fromEntries(fieldsToUnset.map((field) => [field, '-']));
// Example unsetObject = {
// "testObj.del1": "-"
// }
set(rawPayload, `user_properties.$unset`, unsetObject);
}
return rawPayload;
};

Expand Down Expand Up @@ -334,7 +343,7 @@ const getResponseData = (evType, destination, rawPayload, message, groupInfo) =>
case EventType.IDENTIFY:
// event_type for identify event is $identify
rawPayload.event_type = IDENTIFY_AM;
identifyBuilder(message, destination, rawPayload);
rawPayload = identifyBuilder(message, destination, rawPayload);
break;
case EventType.GROUP:
// event_type for identify event is $identify
Expand Down Expand Up @@ -453,6 +462,7 @@ const nonAliasResponsebuilder = (
};
respList.push(groupResponse);
}

anantjain45823 marked this conversation as resolved.
Show resolved Hide resolved
return respList;
};

Expand Down Expand Up @@ -488,6 +498,7 @@ const responseBuilderSimple = (

// 2. get campaign info (only present for JS sdk and http calls)
const campaign = get(message, 'context.campaign') || {};
//
anantjain45823 marked this conversation as resolved.
Show resolved Hide resolved
const initialRef = {
initial_referrer: get(message, 'context.page.initial_referrer'),
initial_referring_domain: get(message, 'context.page.initial_referring_domain'),
Expand Down
14 changes: 11 additions & 3 deletions test/integrations/destinations/am/processor/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,10 @@ export const data = [
{
message: {
channel: 'web',
integrations: {
Amplitude: { fieldsToUnset: ['email'] },
All: true,
},
context: {
externalId: [
{
Expand Down Expand Up @@ -562,9 +566,6 @@ export const data = [
originalTimestamp: '2019-10-14T09:03:17.562Z',
anonymousId: '123456',
userId: '123456',
integrations: {
All: true,
},
sentAt: '2019-10-14T09:03:22.563Z',
},
metadata: {
Expand Down Expand Up @@ -616,6 +617,9 @@ export const data = [
insert_id: '84e26acc-56a5-4835-8233-591137fca468',
ip: '0.0.0.0',
user_properties: {
$unset: {
email: '-',
},
initial_referrer: 'https://docs.rudderstack.com',
initial_referring_domain: 'docs.rudderstack.com',
anonymousId: '123456',
Expand Down Expand Up @@ -743,6 +747,7 @@ export const data = [
anonymousId: '123456',
userId: '123456',
integrations: {
Amplitude: { fieldsToUnset: ['testObj.unsetField1'] },
All: true,
},
sentAt: '2019-10-14T09:03:22.563Z',
Expand Down Expand Up @@ -791,6 +796,9 @@ export const data = [
insert_id: '84e26acc-56a5-4835-8233-591137fca468',
ip: '0.0.0.0',
user_properties: {
$unset: {
'testObj.unsetField1': '-',
yashasvibajpai marked this conversation as resolved.
Show resolved Hide resolved
},
initial_referrer: 'https://docs.rudderstack.com',
initial_referring_domain: 'docs.rudderstack.com',
anonymousId: '123456',
Expand Down
Loading