Skip to content

Commit 7294b76

Browse files
feat: Add support for Google Click Ids
1 parent b8a1a8f commit 7294b76

File tree

3 files changed

+70
-1
lines changed

3 files changed

+70
-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: 29 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,33 @@ 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+
jest.spyOn(Date, 'now').mockImplementation(() => 42);
74+
75+
const url = new URL('https://www.example.com/?gclid=54321&gbraid=67890&wbraid=09876');
76+
77+
window.location.href = url.href;
78+
window.location.search = url.search;
79+
80+
const integrationCapture = new IntegrationCapture();
81+
integrationCapture.capture();
82+
83+
expect(integrationCapture.clickIds).toEqual({
84+
gclid: '54321',
85+
gbraid: '67890',
86+
wbraid: '09876',
87+
});
88+
});
89+
});
90+
91+
describe('Facebook Click Ids', () => {
6892
it('should format fbclid correctly', () => {
6993
jest.spyOn(Date, 'now').mockImplementation(() => 42);
7094

@@ -147,6 +171,7 @@ describe('Integration Capture', () => {
147171
fbclid: 'fb.2.42.12345',
148172
});
149173
});
174+
});
150175

151176
});
152177

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

185210
expect(clickIds).toEqual({
186211
fbclid: 'fb.2.42.67890',
212+
gclid: '54321',
187213
});
188214
});
189215

@@ -259,13 +285,15 @@ describe('Integration Capture', () => {
259285
integrationCapture.clickIds = {
260286
fbclid: '67890',
261287
_fbp: '54321',
288+
gclid: '123233.23131',
262289
};
263290

264291
const customFlags = integrationCapture.getClickIdsAsCustomFlags();
265292

266293
expect(customFlags).toEqual({
267294
'Facebook.ClickId': '67890',
268295
'Facebook.BrowserId': '54321',
296+
'GoogleEnhancedConversions.Gclid': '123233.23131',
269297
});
270298
});
271299

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)