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 support for Google Click Ids #957

Merged
merged 1 commit into from
Dec 11, 2024
Merged
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
13 changes: 13 additions & 0 deletions src/integrationCapture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ interface IntegrationIdMapping {
}

const integrationMapping: IntegrationIdMapping = {
// Facebook / Meta
fbclid: {
mappedKey: 'Facebook.ClickId',
processor: facebookClickIdProcessor,
Expand All @@ -66,6 +67,18 @@ const integrationMapping: IntegrationIdMapping = {
_fbc: {
mappedKey: 'Facebook.ClickId',
},

// Google
gclid: {
mappedKey: 'GoogleEnhancedConversions.Gclid',
},
gbraid: {
mappedKey: 'GoogleEnhancedConversions.Gbraid',
},
wbraid: {
mappedKey: 'GoogleEnhancedConversions.Wbraid',
},

};

export default class IntegrationCapture {
Expand Down
28 changes: 27 additions & 1 deletion test/jest/integration-capture.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ describe('Integration Capture', () => {
it('should pass all clickIds to clickIds object', () => {
jest.spyOn(Date, 'now').mockImplementation(() => 42);

const url = new URL('https://www.example.com/?fbclid=12345&');
const url = new URL('https://www.example.com/?fbclid=12345&gclid=54321&gbraid=67890&wbraid=09876');

window.document.cookie = '_cookie1=1234';
window.document.cookie = '_cookie2=39895811.9165333198';
Expand All @@ -62,9 +62,31 @@ describe('Integration Capture', () => {
expect(integrationCapture.clickIds).toEqual({
fbclid: 'fb.2.42.12345',
_fbp: '54321',
gclid: '54321',
gbraid: '67890',
wbraid: '09876',
});
});

describe('Google Click Ids', () => {
it('should capture Google specific click ids', () => {
const url = new URL('https://www.example.com/?gclid=54321&gbraid=67890&wbraid=09876');

window.location.href = url.href;
window.location.search = url.search;

const integrationCapture = new IntegrationCapture();
integrationCapture.capture();

expect(integrationCapture.clickIds).toEqual({
gclid: '54321',
gbraid: '67890',
wbraid: '09876',
});
});
});

describe('Facebook Click Ids', () => {
it('should format fbclid correctly', () => {
jest.spyOn(Date, 'now').mockImplementation(() => 42);

Expand Down Expand Up @@ -147,6 +169,7 @@ describe('Integration Capture', () => {
fbclid: 'fb.2.42.12345',
});
});
});

});

Expand Down Expand Up @@ -184,6 +207,7 @@ describe('Integration Capture', () => {

expect(clickIds).toEqual({
fbclid: 'fb.2.42.67890',
gclid: '54321',
});
});

Expand Down Expand Up @@ -259,13 +283,15 @@ describe('Integration Capture', () => {
integrationCapture.clickIds = {
fbclid: '67890',
_fbp: '54321',
gclid: '123233.23131',
};

const customFlags = integrationCapture.getClickIdsAsCustomFlags();

expect(customFlags).toEqual({
'Facebook.ClickId': '67890',
'Facebook.BrowserId': '54321',
'GoogleEnhancedConversions.Gclid': '123233.23131',
});
});

Expand Down
28 changes: 28 additions & 0 deletions test/src/tests-integration-capture.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ describe('Integration Capture', () => {
// Mock the query params capture function because we cannot mock window.location.href
sinon.stub(window.mParticle.getInstance()._IntegrationCapture, 'getQueryParams').returns({
fbclid: '1234',
gclid: '234',
gbraid: '6574',
wbraid: '1234111',
});

mParticle.init(apiKey, window.mParticle.config);
Expand Down Expand Up @@ -59,9 +62,13 @@ describe('Integration Capture', () => {
expect(testEvent).to.have.property('data');
expect(testEvent.data).to.have.property('event_name', 'Test Event');
expect(testEvent.data).to.have.property('custom_flags');

expect(testEvent.data.custom_flags).to.deep.equal({
'Facebook.ClickId': `fb.1.${initialTimestamp}.1234`,
'Facebook.BrowserId': '54321',
'GoogleEnhancedConversions.Gclid': '234',
'GoogleEnhancedConversions.Gbraid': '6574',
'GoogleEnhancedConversions.Wbraid': '1234111',
});
});

Expand All @@ -83,6 +90,9 @@ describe('Integration Capture', () => {
expect(testEvent.data.custom_flags).to.deep.equal({
'Facebook.ClickId': 'passed-in',
'Facebook.BrowserId': '54321',
'GoogleEnhancedConversions.Gclid': '234',
'GoogleEnhancedConversions.Gbraid': '6574',
'GoogleEnhancedConversions.Wbraid': '1234111',
});
});

Expand All @@ -104,6 +114,9 @@ describe('Integration Capture', () => {
expect(testEvent.data.custom_flags).to.deep.equal({
'Facebook.ClickId': `fb.1.${initialTimestamp}.1234`,
'Facebook.BrowserId': '54321',
'GoogleEnhancedConversions.Gclid': '234',
'GoogleEnhancedConversions.Gbraid': '6574',
'GoogleEnhancedConversions.Wbraid': '1234111',
});
});

Expand All @@ -123,6 +136,9 @@ describe('Integration Capture', () => {
expect(testEvent.data.custom_flags).to.deep.equal({
'Facebook.ClickId': 'passed-in',
'Facebook.BrowserId': '54321',
'GoogleEnhancedConversions.Gclid': '234',
'GoogleEnhancedConversions.Gbraid': '6574',
'GoogleEnhancedConversions.Wbraid': '1234111',
});
});

Expand Down Expand Up @@ -158,6 +174,9 @@ describe('Integration Capture', () => {
foo: 'bar',
'Facebook.ClickId': `fb.1.${initialTimestamp}.1234`,
'Facebook.BrowserId': '54321',
'GoogleEnhancedConversions.Gclid': '234',
'GoogleEnhancedConversions.Gbraid': '6574',
'GoogleEnhancedConversions.Wbraid': '1234111',
});
});

Expand Down Expand Up @@ -193,6 +212,9 @@ describe('Integration Capture', () => {
expect(testEvent.data.custom_flags).to.deep.equal({
'Facebook.ClickId': 'passed-in',
'Facebook.BrowserId': '54321',
'GoogleEnhancedConversions.Gclid': '234',
'GoogleEnhancedConversions.Gbraid': '6574',
'GoogleEnhancedConversions.Wbraid': '1234111',
});
});

Expand Down Expand Up @@ -228,6 +250,9 @@ describe('Integration Capture', () => {
foo: 'bar',
'Facebook.ClickId': `fb.1.${initialTimestamp}.1234`,
'Facebook.BrowserId': '54321',
'GoogleEnhancedConversions.Gclid': '234',
'GoogleEnhancedConversions.Gbraid': '6574',
'GoogleEnhancedConversions.Wbraid': '1234111',
});
});

Expand Down Expand Up @@ -263,6 +288,9 @@ describe('Integration Capture', () => {
expect(testEvent.data.custom_flags).to.deep.equal({
'Facebook.ClickId': 'passed-in',
'Facebook.BrowserId': '54321',
'GoogleEnhancedConversions.Gclid': '234',
'GoogleEnhancedConversions.Gbraid': '6574',
'GoogleEnhancedConversions.Wbraid': '1234111',
});
});
});
Loading