Skip to content

Commit 1dee593

Browse files
Allow configuring Data Processing Options in facebook-pixel
Facebook released a Limitited Data Use feature, to aid with CCPA compliance. This commit allows enabling (or disabling) the LDU via configuration.
1 parent 3a275b0 commit 1dee593

File tree

3 files changed

+34
-3
lines changed

3 files changed

+34
-3
lines changed

README.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,14 @@ Writing your own adapters for currently unsupported analytics services is easy t
4848
1. `Facebook Pixel`
4949

5050
- `id`: [ID](https://www.facebook.com/ads/manager/pixel/facebook_pixel/?act=129849836&pid=p1)
51+
- dataProcessingOptions: _optional_ An object defining the method, country and state for [data processing options](https://developers.facebook.com/docs/marketing-apis/data-processing-options/)
52+
```js
53+
dataProcessingOptions: {
54+
method: ['LDU'],
55+
country: 1,
56+
state: 1000
57+
}
58+
```
5159

5260
#### Community adapters
5361

@@ -124,7 +132,12 @@ module.exports = function(environment) {
124132
name: 'FacebookPixel',
125133
environments: ['production'],
126134
config: {
127-
id: '1234567890'
135+
id: '1234567890',
136+
dataProcessingOptions: {
137+
method: ['LDU'],
138+
country: 1,
139+
state: 1000
140+
}
128141
}
129142
},
130143

addon/metrics-adapters/facebook-pixel.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export default BaseAdapter.extend({
1111
},
1212

1313
init() {
14-
const { id } = this.config;
14+
const { id, dataProcessingOptions } = this.config;
1515

1616
assert(`[ember-metrics] You must pass a valid \`id\` to the ${this.toString()} adapter`, id);
1717

@@ -27,6 +27,11 @@ export default BaseAdapter.extend({
2727
document,'script','https://connect.facebook.net/en_US/fbevents.js');
2828
/* eslint-enable */
2929

30+
if (dataProcessingOptions) {
31+
const { method, country, state } = dataProcessingOptions;
32+
window.fbq('dataProcessingOptions', method, country, state);
33+
}
34+
3035
window.fbq('init', id);
3136

3237
// Leave this call due to Facebook API docs

tests/unit/metrics-adapters/facebook-pixel-test.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,12 @@ module('facebook-pixel adapter', function(hooks) {
1111

1212
hooks.beforeEach(function() {
1313
config = {
14-
id: '1234567890'
14+
id: '1234567890',
15+
dataProcessingOptions: {
16+
method: ['LDU'],
17+
country: 1,
18+
state: 1000,
19+
}
1520
};
1621

1722
subject = this.owner.factoryFor('ember-metrics@metrics-adapter:facebook-pixel').create({ config });
@@ -58,4 +63,12 @@ module('facebook-pixel adapter', function(hooks) {
5863
subject.trackPage({ page: '/my-page', title: 'My Title' });
5964
assert.ok(fbq.calledWith('track', 'PageView', { page: '/my-page', title: 'My Title' }), 'it sends the correct arguments and options');
6065
});
66+
67+
test("#init calls `fbq` with dataProcessingOptions", function(assert) {
68+
let { dataProcessingOptions, dataProcessingCountry, dataProcessingState } = fbq.instance.pluginConfig._configStore.dataProcessingOptions.global;
69+
70+
assert.ok((dataProcessingOptions == 'LDU'), 'it sends the correct Data Processing Options');
71+
assert.ok((dataProcessingCountry == 1), 'it sends the correct Data Processing Country');
72+
assert.ok((dataProcessingState == 1000), 'it sends the correct Data Processing State');
73+
});
6174
});

0 commit comments

Comments
 (0)