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 autoConfig support in FBPixel, add tests #1702

Merged
merged 2 commits into from
Apr 26, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
@@ -1,6 +1,8 @@
import FacebookPixel from '../../../src/integrations/FacebookPixel/browser';

beforeAll(() => {});
beforeAll(() => {
window.fbq = jest.fn();
});

afterAll(() => {
jest.restoreAllMocks();
Expand Down Expand Up @@ -57,7 +59,7 @@ describe('FacebookPixel init tests', () => {
});
});

test('Testing init call of Facebook Pixel with identified user and updated mapping false', () => {
test('Testing init call of Facebook Pixel with identified user and updated mapping false and autoConfig configured', () => {
const mockAnalytics = {
getUserTraits: jest.fn(() => ({
firstName: 'rudder',
Expand All @@ -68,12 +70,13 @@ describe('FacebookPixel init tests', () => {
getUserId: jest.fn(() => 'testUserID'),
};
facebookPixel = new FacebookPixel(
{ pixelId: '12567839', advancedMapping: true, useUpdatedMapping: false },
{ pixelId: '12567839', advancedMapping: true, useUpdatedMapping: false, autoConfig: true },
mockAnalytics,
destinationInfo,
);
facebookPixel.init();
expect(typeof window.fbq).toBe('function');
expect(window.fbq).toHaveBeenCalledWith('set', 'autoConfig', true, '12567839');
expect(facebookPixel.userPayload).toStrictEqual({
email: '[email protected]',
firstName: 'rudder',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class FacebookPixel {
if (analytics.logLevel) {
logger.setLogLevel(analytics.logLevel);
}
this.autoConfig = config.autoConfig;
this.blacklistPiiProperties = config.blacklistPiiProperties;
this.categoryToContent = config.categoryToContent || [];
this.pixelId = config.pixelId;
Expand Down Expand Up @@ -72,6 +73,7 @@ class FacebookPixel {
window.fbq.allowDuplicatePageViews = true; // enables fb
window.fbq.version = '2.0';
window.fbq.queue = [];
window.fbq('set', 'autoConfig', this.autoConfig, this.pixelId); // toggle autoConfig : sends button click and page metadata
if (this.advancedMapping) {
if (this.useUpdatedMapping) {
const userData = {
Expand Down