Skip to content

Commit

Permalink
fix: age format snapPixel (#1933)
Browse files Browse the repository at this point in the history
  • Loading branch information
aashishmalik authored Nov 21, 2024
1 parent 8150881 commit c9248cb
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ describe('SnapPixel', () => {
email: '[email protected]',
firstName: 'John',
city: 'San Francisco',
age: '16'
},
},
},
Expand All @@ -153,6 +154,50 @@ describe('SnapPixel', () => {
snapPixel.identify(rudderElement);

// Verify only provided parameters are included
expect(window.snaptr.mock.calls[1]).toEqual([
'init',
'12345',
{
user_email: '[email protected]',
firstname: 'John',
geo_city: 'San Francisco',
age: '16'
},
]);
});

it('should skip age if in object format', () => {
const destinationConfig = {
pixelId: '12345',
deduplicationKey: 'email',
hashMethod: false,
enableDeduplication: false,
eventMappingFromConfig: false,
};

const analytics = {
logLevel: 'debug',
getAnonymousId: () => 'ANONYMOUS_ID',
};

const rudderElement = {
message: {
context: {
traits: {
email: '[email protected]',
firstName: 'John',
city: 'San Francisco',
age: {
a: 1,
},
},
},
},
};
const snapPixel = new SnapPixel(destinationConfig, analytics, destinationInfo);
snapPixel.init();
snapPixel.identify(rudderElement);

expect(window.snaptr.mock.calls[1]).toEqual([
'init',
'12345',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +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';
import { getDefinedTraits } from '../../utils/utils';

const logger = new Logger(DISPLAY_NAME);

Expand Down Expand Up @@ -117,7 +117,8 @@ class SnapPixel {
if (ipAddress) payload.ip_address = ipAddress;
if (firstName) payload.firstname = firstName;
if (lastName) payload.lastname = lastName;
if (age) payload.age = age;
if (age && (typeof age === 'number' || (!isNaN(Number(age)) && typeof age === 'string')))
payload.age = age;
if (city) payload.geo_city = city;
if (state) payload.geo_region = state;
if (postalCode) payload.geo_postal_code = postalCode;
Expand Down

0 comments on commit c9248cb

Please sign in to comment.