Skip to content

Commit

Permalink
Merge branch 'develop' into feat.ga4-consent-mode
Browse files Browse the repository at this point in the history
  • Loading branch information
mihir-4116 authored Mar 18, 2024
2 parents ea9dcfc + 5e4ddbd commit 1560a51
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 1 deletion.
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');
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

0 comments on commit 1560a51

Please sign in to comment.