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: snap extra parametrs pass #1921

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
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ describe('getDefinedTraits Tests', () => {
name: 'rudder stack',
phone: undefined,
state: undefined,
postalCode: undefined,
userId: 'user123',
userIdOnly: 'user123',
});
Expand Down Expand Up @@ -327,7 +328,7 @@ describe('flattenJsonPayload Tests', () => {
const testObj = { prop1: { prop2: 'abc' } };
testObj.prop3 = testObj;
const result = utils.flattenJsonPayload(testObj);
expect(result).toStrictEqual({ 'prop1.prop2': 'abc', "prop3": "[Circular Reference]" });
expect(result).toStrictEqual({ 'prop1.prop2': 'abc', prop3: '[Circular Reference]' });
});
test('test case with specified delimeter', () => {
const testObj = { prop1: { prop2: 'abc' } };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
} from '../../utils/commonUtils';
import { ecommEventPayload, eventPayload, getUserEmailAndPhone, sendEvent } from './util';
import { loadNativeSdk } from './nativeSdkLoader';
import { getDefinedTraits } from '@rudderstack/analytics-js-integrations/utils/utils';

const logger = new Logger(DISPLAY_NAME);

Expand Down Expand Up @@ -99,6 +100,8 @@
const userEmail = get(message, 'context.traits.email');
const userPhoneNumber = get(message, 'context.traits.phone');
const ipAddress = get(message, 'context.ip') || get(message, 'request_ip');
const age = get(message, 'context.traits.age');
const { firstName, lastName, postalCode, country, city, state } = getDefinedTraits(message);

Check warning on line 104 in packages/analytics-js-integrations/src/integrations/SnapPixel/browser.js

View check run for this annotation

Codecov / codecov/patch

packages/analytics-js-integrations/src/integrations/SnapPixel/browser.js#L103-L104

Added lines #L103 - L104 were not covered by tests
let payload = {};

if (!userEmail && !userPhoneNumber && !ipAddress) {
Expand All @@ -109,7 +112,17 @@
}

payload = getUserEmailAndPhone(this.hashMethod, userEmail, userPhoneNumber);
payload = { ...payload, ip_address: ipAddress };
payload = {

Check warning on line 115 in packages/analytics-js-integrations/src/integrations/SnapPixel/browser.js

View check run for this annotation

Codecov / codecov/patch

packages/analytics-js-integrations/src/integrations/SnapPixel/browser.js#L115

Added line #L115 was not covered by tests
...payload,
ip_address: ipAddress,
firstname: firstName,
lastname: lastName,
age,
geo_city: city,
geo_region: state,
geo_postal_code: postalCode,
geo_country: country,
};

payload = removeUndefinedAndNullValues(payload);
window.snaptr('init', this.pixelId, payload);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {
ADD_TO_CART_EVENT,
CHECK_OUT_EVENT,
LEAD_EVENT,
} from '@rudderstack/analytics-js-common/constants/integrations/CommonIntegrationsConstant/constants'
} from '@rudderstack/analytics-js-common/constants/integrations/CommonIntegrationsConstant/constants';
import { ScriptLoader } from '@rudderstack/analytics-js-common/v1.1/utils/ScriptLoader';
import Logger from '../../utils/logger';
import {
Expand Down
9 changes: 8 additions & 1 deletion packages/analytics-js-integrations/src/utils/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ function recurse(cur, prop, result, visited = new Set()) {
};

if (visited.has(cur)) {
res[prop] = "[Circular Reference]";
res[prop] = '[Circular Reference]';
return result;
}

Expand Down Expand Up @@ -271,6 +271,13 @@ function getDefinedTraits(message) {
get(message, 'context.traits.Country') ||
get(message, 'context.traits.address.country') ||
get(message, 'context.traits.address.Country'),
postalCode:
get(message, 'context.traits.postalCode') ||
get(message, 'context.traits.postalcode') ||
get(message, 'context.traits.postal_code') ||
get(message, 'context.traits.address.postalCode') ||
get(message, 'context.traits.address.postal_code') ||
get(message, 'context.traits.address.postalcode'),
};

if (!get(traitsValue, 'name') && get(traitsValue, 'firstName') && get(traitsValue, 'lastName')) {
Expand Down