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: add support of skip_user_properties_sync on Amplitude #3181

Merged
merged 4 commits into from
Mar 18, 2024
Merged
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: 3 additions & 0 deletions src/v0/destinations/am/transform.js
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,9 @@ const responseBuilderSimple = (
...campaign,
};

// we are updating the payload with skip_user_properties_sync
AMUtils.updateWithSkipAttribute(message, rawPayload);

const respData = getResponseData(evType, destination, rawPayload, message, groupInfo);
const { groups, rawPayload: updatedRawPayload } = respData;

Expand Down
35 changes: 34 additions & 1 deletion src/v0/destinations/am/util.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
const { getUnsetObj, validateEventType, userPropertiesPostProcess } = require('./utils');
const {
getUnsetObj,
validateEventType,
userPropertiesPostProcess,
updateWithSkipAttribute,
} = require('./utils');

describe('getUnsetObj', () => {
it("should return undefined when 'message.integrations.Amplitude.fieldsToUnset' is not array", () => {
Expand Down Expand Up @@ -164,3 +169,31 @@ describe('userPropertiesPostProcess', () => {
});
});
});

describe('updateWithSkipAttribute', () => {
// when 'skipUserPropertiesSync ' is present in 'integrations.Amplitude', return the original payload.
it("should return the original payload when 'skipUserPropertiesSync' is present", () => {
const message = { integrations: { Amplitude: { skipUserPropertiesSync: true } } };
const payload = { key: 'value' };
const expectedPayload = { key: 'value', $skip_user_properties_sync: true };
updateWithSkipAttribute(message, payload);
expect(expectedPayload).toEqual(payload);
});

// When 'skipUserPropertiesSync' is not present in 'integrations.Amplitude', return the original payload.
it("should return the original payload when 'skipUserPropertiesSync' is not present", () => {
const message = { integrations: { Amplitude: {} } };
const payload = { key: 'value' };
const expectedPayload = { key: 'value' };
updateWithSkipAttribute(message, payload);
expect(payload).toEqual(expectedPayload);
});
// When 'message' is null, return null.
it("should return null when 'message' is null", () => {
const message = null;
const payload = { key: 'value' };
const expectedPayload = { key: 'value' };
updateWithSkipAttribute(message, payload);
expect(payload).toEqual(expectedPayload);
});
});
9 changes: 9 additions & 0 deletions src/v0/destinations/am/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
const get = require('get-value');
const uaParser = require('@amplitude/ua-parser-js');
const { InstrumentationError } = require('@rudderstack/integrations-lib');
const set = require('set-value');
const logger = require('../../../logger');
const { isDefinedAndNotNull } = require('../../util');

Expand Down Expand Up @@ -110,6 +111,13 @@ const getUnsetObj = (message) => {
return unsetObject;
};

const updateWithSkipAttribute = (message, payload) => {
const skipAttribute = get(message, 'integrations.Amplitude.skipUserPropertiesSync');
ItsSudip marked this conversation as resolved.
Show resolved Hide resolved
if (skipAttribute) {
set(payload, '$skip_user_properties_sync', true);
}
};

/**
* Check for evType as in some cases, like when the page name is absent,
* either the template depends only on the event.name or there is no template provided by user
Expand Down Expand Up @@ -187,4 +195,5 @@ module.exports = {
getUnsetObj,
validateEventType,
userPropertiesPostProcess,
updateWithSkipAttribute,
};
3 changes: 3 additions & 0 deletions test/integrations/destinations/am/processor/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10739,6 +10739,7 @@ export const data = [
integrations: {
All: true,
Amplitude: {
skipUserPropertiesSync: false,
event_id: 2,
},
},
Expand Down Expand Up @@ -10894,6 +10895,7 @@ export const data = [
integrations: {
All: true,
Amplitude: {
skipUserPropertiesSync: true,
event_id: 2,
},
},
Expand Down Expand Up @@ -10949,6 +10951,7 @@ export const data = [
insert_id: '5e10d13a-bf9a-44bf-b884-43a9e591ea71',
ip: '1.1.1.1',
event_id: 2,
$skip_user_properties_sync: true,
user_properties: {
initial_referrer: 'https://docs.rudderstack.com',
initial_referring_domain: 'docs.rudderstack.com',
Expand Down
Loading