From f03c5ed1dcea9e73697be6808f7cd0f8021fc0a5 Mon Sep 17 00:00:00 2001 From: Alex S <49695018+alexs-mparticle@users.noreply.github.com> Date: Wed, 11 Dec 2024 11:47:23 -0500 Subject: [PATCH] feat: Add support for Google Click Ids (#955) (#957) --- src/integrationCapture.ts | 13 +++++++++++++ test/jest/integration-capture.spec.ts | 28 ++++++++++++++++++++++++++- test/src/tests-integration-capture.ts | 28 +++++++++++++++++++++++++++ 3 files changed, 68 insertions(+), 1 deletion(-) diff --git a/src/integrationCapture.ts b/src/integrationCapture.ts index 7799b6e3..a4809b44 100644 --- a/src/integrationCapture.ts +++ b/src/integrationCapture.ts @@ -56,6 +56,7 @@ interface IntegrationIdMapping { } const integrationMapping: IntegrationIdMapping = { + // Facebook / Meta fbclid: { mappedKey: 'Facebook.ClickId', processor: facebookClickIdProcessor, @@ -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 { diff --git a/test/jest/integration-capture.spec.ts b/test/jest/integration-capture.spec.ts index cef4f972..d219d136 100644 --- a/test/jest/integration-capture.spec.ts +++ b/test/jest/integration-capture.spec.ts @@ -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'; @@ -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); @@ -147,6 +169,7 @@ describe('Integration Capture', () => { fbclid: 'fb.2.42.12345', }); }); + }); }); @@ -184,6 +207,7 @@ describe('Integration Capture', () => { expect(clickIds).toEqual({ fbclid: 'fb.2.42.67890', + gclid: '54321', }); }); @@ -259,6 +283,7 @@ describe('Integration Capture', () => { integrationCapture.clickIds = { fbclid: '67890', _fbp: '54321', + gclid: '123233.23131', }; const customFlags = integrationCapture.getClickIdsAsCustomFlags(); @@ -266,6 +291,7 @@ describe('Integration Capture', () => { expect(customFlags).toEqual({ 'Facebook.ClickId': '67890', 'Facebook.BrowserId': '54321', + 'GoogleEnhancedConversions.Gclid': '123233.23131', }); }); diff --git a/test/src/tests-integration-capture.ts b/test/src/tests-integration-capture.ts index 9b6cf403..d8c78bc0 100644 --- a/test/src/tests-integration-capture.ts +++ b/test/src/tests-integration-capture.ts @@ -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); @@ -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', }); }); @@ -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', }); }); @@ -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', }); }); @@ -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', }); }); @@ -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', }); }); @@ -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', }); }); @@ -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', }); }); @@ -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', }); }); }); \ No newline at end of file