Skip to content

Commit a5f905a

Browse files
gpsamsonmloar
andauthored
Support Limited Data Use in Facebook Pixel (#493)
* Support Limited Data Use in Facebook Pixel * Add test case for disabled limited data use * [FB Pixel] Bump version Co-authored-by: Matt Loar <matt@loar.name>
1 parent 32b6ab4 commit a5f905a

File tree

4 files changed

+39
-1
lines changed

4 files changed

+39
-1
lines changed

integrations/facebook-pixel/HISTORY.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
2.11.0/ 2020-07-16
2+
==================
3+
4+
* Add support for Limited Data Use. See: https://developers.facebook.com/docs/marketing-apis/data-processing-options
5+
16
2.10.0/ 2019-12-04
27
==================
38

integrations/facebook-pixel/lib/index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ var FacebookPixel = (module.exports = integration('Facebook Pixel')
3030
.option('standardEventsCustomProperties', [])
3131
.option('keyForExternalId', '')
3232
.option('userIdAsExternalId', false)
33+
.option('limitedDataUse', true)
3334
.mapping('standardEvents')
3435
.mapping('legacyEvents')
3536
.mapping('contentTypes')
@@ -102,6 +103,9 @@ FacebookPixel.prototype.initialize = function() {
102103
if (!this.options.automaticConfiguration) {
103104
window.fbq('set', 'autoConfig', false, this.options.pixelId);
104105
}
106+
if (this.options.limitedDataUse) {
107+
window.fbq('dataProcessingOptions', ['LDU'], 0, 0);
108+
}
105109
if (this.options.initWithExistingTraits) {
106110
var traits = this.formatTraits(this.analytics);
107111
window.fbq('init', this.options.pixelId, traits);

integrations/facebook-pixel/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@segment/analytics.js-integration-facebook-pixel",
33
"description": "The Facebook Pixel analytics.js integration.",
4-
"version": "2.10.0",
4+
"version": "2.11.0",
55
"keywords": [
66
"analytics.js",
77
"analytics.js-integration",

integrations/facebook-pixel/test/index.test.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ describe('Facebook Pixel', function() {
3535
pixelId: '123123123',
3636
agent: 'test',
3737
initWithExistingTraits: false,
38+
limitedDataUse: true,
3839
whitelistPiiProperties: [],
3940
blacklistPiiProperties: [],
4041
standardEventsCustomProperties: []
@@ -147,6 +148,12 @@ describe('Facebook Pixel', function() {
147148
);
148149
});
149150

151+
it('should call dataProcessingOptions if limitedDataUse is enabled', function() {
152+
analytics.stub(window, 'fbq');
153+
analytics.initialize();
154+
analytics.called(window.fbq, 'dataProcessingOptions', ['LDU'], 0, 0);
155+
});
156+
150157
before(function() {
151158
options.initWithExistingTraits = true;
152159
});
@@ -171,6 +178,28 @@ describe('Facebook Pixel', function() {
171178
analytics.called(window.fbq, 'init', options.pixelId, payload);
172179
});
173180
});
181+
182+
describe('#initialize without LDU', function() {
183+
before(function() {
184+
options.limitedDataUse = false;
185+
});
186+
187+
after(function() {
188+
options.limitedDataUse = true;
189+
});
190+
191+
it('should not call dataProcessingOptions if limitedDataUse is false', function() {
192+
analytics.stub(window, 'fbq');
193+
analytics.initialize();
194+
analytics.didNotCall(
195+
window.fbq,
196+
'dataProcessingOptions',
197+
['LDU'],
198+
0,
199+
0
200+
);
201+
});
202+
});
174203
});
175204

176205
describe('loading', function() {

0 commit comments

Comments
 (0)