Skip to content

Commit a5032f2

Browse files
committed
Adding support for bot filtering. WIP.
1 parent 7988063 commit a5032f2

File tree

4 files changed

+32
-5
lines changed

4 files changed

+32
-5
lines changed

packages/optimizely-sdk/lib/core/event_builder/index.js

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2016-2017, Optimizely
2+
* Copyright 2016-2018, Optimizely
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -19,10 +19,12 @@ var eventTagUtils = require('../../utils/event_tag_utils');
1919
var projectConfig = require('../project_config');
2020

2121
var ACTIVATE_EVENT_KEY = 'campaign_activated';
22+
var BOT_FILTERING_FEATURE_KEY = '$opt_bot_filtering';
2223
var CUSTOM_ATTRIBUTE_FEATURE_TYPE = 'custom';
2324
var ENDPOINT = 'https://logx.optimizely.com/v1/events';
2425
var HTTP_VERB = 'POST';
2526

27+
2628
/**
2729
* Get params which are used same in both conversion and impression events
2830
* @param {Object} options.attributes Object representing user attributes and values which need to be recorded
@@ -36,7 +38,7 @@ function getCommonEventParams(options) {
3638
var attributes = options.attributes;
3739
var configObj = options.configObj;
3840
var anonymize_ip = configObj.anonymizeIP;
39-
41+
var botFiltering = configObj.botFiltering;
4042
if (anonymize_ip === null || anonymize_ip === undefined) {
4143
anonymize_ip = false;
4244
}
@@ -60,15 +62,30 @@ function getCommonEventParams(options) {
6062
fns.forOwn(attributes, function(attributeValue, attributeKey){
6163
var attributeId = projectConfig.getAttributeId(options.configObj, attributeKey);
6264
if (attributeId) {
63-
var feature = {
65+
commonParams.visitors[0].attributes.push({
6466
entity_id: attributeId,
6567
key: attributeKey,
6668
type: CUSTOM_ATTRIBUTE_FEATURE_TYPE,
6769
value: attributes[attributeKey],
68-
};
69-
commonParams.visitors[0].attributes.push(feature);
70+
});
71+
} else if (enums.RESERVED_ATTRIBUTES.hasOwnProperty(attributeKey)) {
72+
commonParams.visitors[0].attributes.push({
73+
entity_id: attributeKey,
74+
key: attributeKey,
75+
type: CUSTOM_ATTRIBUTE_FEATURE_TYPE,
76+
value: attributes[attributeKey],
77+
});
7078
}
7179
});
80+
81+
if (typeof botFiltering === 'boolean') {
82+
commonParams.visitors[0].attributes.push({
83+
entity_id: BOT_FILTERING_FEATURE_KEY,
84+
key: BOT_FILTERING_FEATURE_KEY,
85+
type: CUSTOM_ATTRIBUTE_FEATURE_TYPE,
86+
value: botFiltering,
87+
});
88+
};
7289
return commonParams;
7390
}
7491

packages/optimizely-sdk/lib/optimizely/index.tests.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2549,6 +2549,11 @@ describe('lib/optimizely', function() {
25492549
'key': 'test_attribute',
25502550
'type': 'custom',
25512551
'value': 'test_value',
2552+
}, {
2553+
'entity_id': '$opt_bot_filtering',
2554+
'key': '$opt_bot_filtering',
2555+
'type': 'custom',
2556+
'value': true,
25522557
},
25532558
],
25542559
}

packages/optimizely-sdk/lib/tests/test_data.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -531,6 +531,7 @@ var configWithFeatures = {
531531
}
532532
],
533533
'anonymizeIP': true,
534+
'botFiltering': true,
534535
'audiences': [
535536
{
536537
'id': '594017',

packages/optimizely-sdk/lib/utils/enums/index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,10 @@ exports.RESERVED_EVENT_KEYWORDS = {
128128
VALUE: 'value',
129129
};
130130

131+
exports.RESERVED_ATTRIBUTES = {
132+
USER_AGENT: '$opt_user_agent',
133+
};
134+
131135
exports.JAVASCRIPT_CLIENT_ENGINE = 'javascript-sdk';
132136
exports.NODE_CLIENT_ENGINE = 'node-sdk';
133137
exports.NODE_CLIENT_VERSION = '2.0.1';

0 commit comments

Comments
 (0)