Skip to content
This repository was archived by the owner on Jun 21, 2023. It is now read-only.

Commit 7847829

Browse files
Introduce changes for bot filtering support (optimizely#99)
1 parent 449849c commit 7847829

File tree

9 files changed

+316
-32
lines changed

9 files changed

+316
-32
lines changed

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/****************************************************************************
2-
* Copyright 2017, Optimizely, Inc. and contributors *
2+
* Copyright 2017-2018, Optimizely, Inc. and contributors *
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. *
@@ -26,7 +26,6 @@ var MODULE_NAME = 'DECISION_SERVICE';
2626
var ERROR_MESSAGES = enums.ERROR_MESSAGES;
2727
var LOG_LEVEL = enums.LOG_LEVEL;
2828
var LOG_MESSAGES = enums.LOG_MESSAGES;
29-
var RESERVED_ATTRIBUTE_KEY_BUCKETING_ID = '$opt_bucketing_id';
3029
var DECISION_SOURCES = enums.DECISION_SOURCES;
3130

3231

@@ -67,8 +66,8 @@ DecisionService.prototype.getVariation = function(experimentKey, userId, attribu
6766

6867
// If the bucketing ID key is defined in attributes, than use that in place of the userID for the murmur hash key
6968
if (!fns.isEmpty(attributes)) {
70-
if (attributes.hasOwnProperty(RESERVED_ATTRIBUTE_KEY_BUCKETING_ID)) {
71-
bucketingId = attributes[RESERVED_ATTRIBUTE_KEY_BUCKETING_ID];
69+
if (attributes.hasOwnProperty(enums.CONTROL_ATTRIBUTES.BUCKETING_ID)) {
70+
bucketingId = attributes[enums.CONTROL_ATTRIBUTES.BUCKETING_ID];
7271
this.logger.log(LOG_LEVEL.DEBUG, sprintf('Setting the bucketing ID to %s.', bucketingId))
7372
}
7473
}

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

Lines changed: 15 additions & 6 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.
@@ -30,13 +30,14 @@ var HTTP_VERB = 'POST';
3030
* @param {string} options.clientVersion The version of the client
3131
* @param {Object} options.configObj Object representing project configuration, including datafile information and mappings for quick lookup
3232
* @param {string} options.userId ID for user
33+
* @param {Object} options.Logger logger
3334
* @return {Object} Common params with properties that are used in both conversion and impression events
3435
*/
3536
function getCommonEventParams(options) {
3637
var attributes = options.attributes;
3738
var configObj = options.configObj;
3839
var anonymize_ip = configObj.anonymizeIP;
39-
40+
var botFiltering = configObj.botFiltering;
4041
if (anonymize_ip === null || anonymize_ip === undefined) {
4142
anonymize_ip = false;
4243
}
@@ -58,17 +59,25 @@ function getCommonEventParams(options) {
5859
};
5960

6061
fns.forOwn(attributes, function(attributeValue, attributeKey){
61-
var attributeId = projectConfig.getAttributeId(options.configObj, attributeKey);
62+
var attributeId = projectConfig.getAttributeId(options.configObj, attributeKey, options.logger);
6263
if (attributeId) {
63-
var feature = {
64+
commonParams.visitors[0].attributes.push({
6465
entity_id: attributeId,
6566
key: attributeKey,
6667
type: CUSTOM_ATTRIBUTE_FEATURE_TYPE,
6768
value: attributes[attributeKey],
68-
};
69-
commonParams.visitors[0].attributes.push(feature);
69+
});
7070
}
7171
});
72+
73+
if (typeof botFiltering === 'boolean') {
74+
commonParams.visitors[0].attributes.push({
75+
entity_id: enums.CONTROL_ATTRIBUTES.BOT_FILTERING,
76+
key: enums.CONTROL_ATTRIBUTES.BOT_FILTERING,
77+
type: CUSTOM_ATTRIBUTE_FEATURE_TYPE,
78+
value: botFiltering,
79+
});
80+
};
7281
return commonParams;
7382
}
7483

0 commit comments

Comments
 (0)