Skip to content

Commit

Permalink
feat: Add support for Google Click Ids (#955) (#957)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexs-mparticle authored Dec 11, 2024
1 parent d2f3645 commit f03c5ed
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 1 deletion.
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',
});
});
});

0 comments on commit f03c5ed

Please sign in to comment.