Skip to content

Commit

Permalink
feat: snap extra parametrs pass
Browse files Browse the repository at this point in the history
  • Loading branch information
aashishmalik committed Nov 14, 2024
1 parent 07909cf commit f2c6374
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
} 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 @@ class SnapPixel {
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);
let payload = {};

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

payload = getUserEmailAndPhone(this.hashMethod, userEmail, userPhoneNumber);
payload = { ...payload, ip_address: ipAddress };
payload = {
...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

0 comments on commit f2c6374

Please sign in to comment.