Skip to content

Commit f6ba224

Browse files
feat: Add support for Google Click Ids (#955)
1 parent b8a1a8f commit f6ba224

File tree

3 files changed

+68
-1
lines changed

3 files changed

+68
-1
lines changed

src/integrationCapture.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ interface IntegrationIdMapping {
5656
}
5757

5858
const integrationMapping: IntegrationIdMapping = {
59+
// Facebook / Meta
5960
fbclid: {
6061
mappedKey: 'Facebook.ClickId',
6162
processor: facebookClickIdProcessor,
@@ -66,6 +67,18 @@ const integrationMapping: IntegrationIdMapping = {
6667
_fbc: {
6768
mappedKey: 'Facebook.ClickId',
6869
},
70+
71+
// Google
72+
gclid: {
73+
mappedKey: 'GoogleEnhancedConversions.Gclid',
74+
},
75+
gbraid: {
76+
mappedKey: 'GoogleEnhancedConversions.Gbraid',
77+
},
78+
wbraid: {
79+
mappedKey: 'GoogleEnhancedConversions.Wbraid',
80+
},
81+
6982
};
7083

7184
export default class IntegrationCapture {

test/jest/integration-capture.spec.ts

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ describe('Integration Capture', () => {
4646
it('should pass all clickIds to clickIds object', () => {
4747
jest.spyOn(Date, 'now').mockImplementation(() => 42);
4848

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

5151
window.document.cookie = '_cookie1=1234';
5252
window.document.cookie = '_cookie2=39895811.9165333198';
@@ -62,9 +62,31 @@ describe('Integration Capture', () => {
6262
expect(integrationCapture.clickIds).toEqual({
6363
fbclid: 'fb.2.42.12345',
6464
_fbp: '54321',
65+
gclid: '54321',
66+
gbraid: '67890',
67+
wbraid: '09876',
6568
});
6669
});
6770

71+
describe('Google Click Ids', () => {
72+
it('should capture Google specific click ids', () => {
73+
const url = new URL('https://www.example.com/?gclid=54321&gbraid=67890&wbraid=09876');
74+
75+
window.location.href = url.href;
76+
window.location.search = url.search;
77+
78+
const integrationCapture = new IntegrationCapture();
79+
integrationCapture.capture();
80+
81+
expect(integrationCapture.clickIds).toEqual({
82+
gclid: '54321',
83+
gbraid: '67890',
84+
wbraid: '09876',
85+
});
86+
});
87+
});
88+
89+
describe('Facebook Click Ids', () => {
6890
it('should format fbclid correctly', () => {
6991
jest.spyOn(Date, 'now').mockImplementation(() => 42);
7092

@@ -147,6 +169,7 @@ describe('Integration Capture', () => {
147169
fbclid: 'fb.2.42.12345',
148170
});
149171
});
172+
});
150173

151174
});
152175

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

185208
expect(clickIds).toEqual({
186209
fbclid: 'fb.2.42.67890',
210+
gclid: '54321',
187211
});
188212
});
189213

@@ -259,13 +283,15 @@ describe('Integration Capture', () => {
259283
integrationCapture.clickIds = {
260284
fbclid: '67890',
261285
_fbp: '54321',
286+
gclid: '123233.23131',
262287
};
263288

264289
const customFlags = integrationCapture.getClickIdsAsCustomFlags();
265290

266291
expect(customFlags).toEqual({
267292
'Facebook.ClickId': '67890',
268293
'Facebook.BrowserId': '54321',
294+
'GoogleEnhancedConversions.Gclid': '123233.23131',
269295
});
270296
});
271297

test/src/tests-integration-capture.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ describe('Integration Capture', () => {
3131
// Mock the query params capture function because we cannot mock window.location.href
3232
sinon.stub(window.mParticle.getInstance()._IntegrationCapture, 'getQueryParams').returns({
3333
fbclid: '1234',
34+
gclid: '234',
35+
gbraid: '6574',
36+
wbraid: '1234111',
3437
});
3538

3639
mParticle.init(apiKey, window.mParticle.config);
@@ -59,9 +62,13 @@ describe('Integration Capture', () => {
5962
expect(testEvent).to.have.property('data');
6063
expect(testEvent.data).to.have.property('event_name', 'Test Event');
6164
expect(testEvent.data).to.have.property('custom_flags');
65+
6266
expect(testEvent.data.custom_flags).to.deep.equal({
6367
'Facebook.ClickId': `fb.1.${initialTimestamp}.1234`,
6468
'Facebook.BrowserId': '54321',
69+
'GoogleEnhancedConversions.Gclid': '234',
70+
'GoogleEnhancedConversions.Gbraid': '6574',
71+
'GoogleEnhancedConversions.Wbraid': '1234111',
6572
});
6673
});
6774

@@ -83,6 +90,9 @@ describe('Integration Capture', () => {
8390
expect(testEvent.data.custom_flags).to.deep.equal({
8491
'Facebook.ClickId': 'passed-in',
8592
'Facebook.BrowserId': '54321',
93+
'GoogleEnhancedConversions.Gclid': '234',
94+
'GoogleEnhancedConversions.Gbraid': '6574',
95+
'GoogleEnhancedConversions.Wbraid': '1234111',
8696
});
8797
});
8898

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

@@ -123,6 +136,9 @@ describe('Integration Capture', () => {
123136
expect(testEvent.data.custom_flags).to.deep.equal({
124137
'Facebook.ClickId': 'passed-in',
125138
'Facebook.BrowserId': '54321',
139+
'GoogleEnhancedConversions.Gclid': '234',
140+
'GoogleEnhancedConversions.Gbraid': '6574',
141+
'GoogleEnhancedConversions.Wbraid': '1234111',
126142
});
127143
});
128144

@@ -158,6 +174,9 @@ describe('Integration Capture', () => {
158174
foo: 'bar',
159175
'Facebook.ClickId': `fb.1.${initialTimestamp}.1234`,
160176
'Facebook.BrowserId': '54321',
177+
'GoogleEnhancedConversions.Gclid': '234',
178+
'GoogleEnhancedConversions.Gbraid': '6574',
179+
'GoogleEnhancedConversions.Wbraid': '1234111',
161180
});
162181
});
163182

@@ -193,6 +212,9 @@ describe('Integration Capture', () => {
193212
expect(testEvent.data.custom_flags).to.deep.equal({
194213
'Facebook.ClickId': 'passed-in',
195214
'Facebook.BrowserId': '54321',
215+
'GoogleEnhancedConversions.Gclid': '234',
216+
'GoogleEnhancedConversions.Gbraid': '6574',
217+
'GoogleEnhancedConversions.Wbraid': '1234111',
196218
});
197219
});
198220

@@ -228,6 +250,9 @@ describe('Integration Capture', () => {
228250
foo: 'bar',
229251
'Facebook.ClickId': `fb.1.${initialTimestamp}.1234`,
230252
'Facebook.BrowserId': '54321',
253+
'GoogleEnhancedConversions.Gclid': '234',
254+
'GoogleEnhancedConversions.Gbraid': '6574',
255+
'GoogleEnhancedConversions.Wbraid': '1234111',
231256
});
232257
});
233258

@@ -263,6 +288,9 @@ describe('Integration Capture', () => {
263288
expect(testEvent.data.custom_flags).to.deep.equal({
264289
'Facebook.ClickId': 'passed-in',
265290
'Facebook.BrowserId': '54321',
291+
'GoogleEnhancedConversions.Gclid': '234',
292+
'GoogleEnhancedConversions.Gbraid': '6574',
293+
'GoogleEnhancedConversions.Wbraid': '1234111',
266294
});
267295
});
268296
});

0 commit comments

Comments
 (0)