optimizely-sdk 2.0.3 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/optimizely/decision_service.rb +3 -5
- data/lib/optimizely/event_builder.rb +27 -27
- data/lib/optimizely/helpers/constants.rb +6 -0
- data/lib/optimizely/notification_center.rb +17 -6
- data/lib/optimizely/project_config.rb +21 -2
- data/lib/optimizely/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 50614c45e6266670a008909d27b7baf89d443500
|
4
|
+
data.tar.gz: 89c89c31817a26ef93d516d19f406c12be5617f2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8e443c5554673b3c209d3a8d85135d843db8e417df827a14d414f954f5eb3bbd70804163d948f48beb1174e909427761fd8e19acf77e2c7d7879fbe2dfcca013
|
7
|
+
data.tar.gz: 52e4ec4502499c9a831590ec0557fd418e09e0b89d2c1f11b786d6685cf8533cdf9820937bfa66778f627f8612ab2a45ac1044be79827c83b49ff4efcc942fcf
|
@@ -18,8 +18,6 @@
|
|
18
18
|
require_relative './bucketer'
|
19
19
|
|
20
20
|
module Optimizely
|
21
|
-
RESERVED_ATTRIBUTE_KEY_BUCKETING_ID = "\$opt_bucketing_id"
|
22
|
-
|
23
21
|
class DecisionService
|
24
22
|
# Optimizely's decision service that determines into which variation of an experiment a user will be allocated.
|
25
23
|
#
|
@@ -368,9 +366,9 @@ module Optimizely
|
|
368
366
|
bucketing_id = user_id
|
369
367
|
|
370
368
|
# If the bucketing ID key is defined in attributes, then use that in place of the userID
|
371
|
-
if attributes && attributes[
|
372
|
-
unless attributes[
|
373
|
-
bucketing_id = attributes[
|
369
|
+
if attributes && attributes[Optimizely::Helpers::Constants::CONTROL_ATTRIBUTES['BUCKETING_ID']].is_a?(String)
|
370
|
+
unless attributes[Optimizely::Helpers::Constants::CONTROL_ATTRIBUTES['BUCKETING_ID']].empty?
|
371
|
+
bucketing_id = attributes[Optimizely::Helpers::Constants::CONTROL_ATTRIBUTES['BUCKETING_ID']]
|
374
372
|
@config.logger.log(Logger::DEBUG, "Setting the bucketing ID '#{bucketing_id}'")
|
375
373
|
end
|
376
374
|
end
|
@@ -22,8 +22,6 @@ require_relative '../optimizely/helpers/event_tag_utils'
|
|
22
22
|
require 'securerandom'
|
23
23
|
|
24
24
|
module Optimizely
|
25
|
-
RESERVED_ATTRIBUTE_KEY_BUCKETING_ID_EVENT_PARAM_KEY = 'optimizely_bucketing_id'
|
26
|
-
|
27
25
|
class Event
|
28
26
|
# Representation of an event which can be sent to the Optimizely logging endpoint.
|
29
27
|
|
@@ -58,6 +56,13 @@ module Optimizely
|
|
58
56
|
|
59
57
|
private
|
60
58
|
|
59
|
+
def bot_filtering
|
60
|
+
# Get bot filtering bool
|
61
|
+
#
|
62
|
+
# Returns 'botFiltering' value in the datafile.
|
63
|
+
@config.bot_filtering
|
64
|
+
end
|
65
|
+
|
61
66
|
def get_common_params(user_id, attributes)
|
62
67
|
# Get params which are used in both conversion and impression events.
|
63
68
|
#
|
@@ -69,33 +74,28 @@ module Optimizely
|
|
69
74
|
visitor_attributes = []
|
70
75
|
|
71
76
|
attributes&.keys&.each do |attribute_key|
|
72
|
-
# Omit null attribute
|
77
|
+
# Omit null attribute values
|
73
78
|
attribute_value = attributes[attribute_key]
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
}
|
85
|
-
else
|
86
|
-
# Skip attributes not in the datafile
|
87
|
-
attribute_id = @config.get_attribute_id(attribute_key)
|
88
|
-
next unless attribute_id
|
89
|
-
|
90
|
-
feature = {
|
91
|
-
entity_id: attribute_id,
|
92
|
-
key: attribute_key,
|
93
|
-
type: CUSTOM_ATTRIBUTE_FEATURE_TYPE,
|
94
|
-
value: attribute_value
|
95
|
-
}
|
96
|
-
|
79
|
+
unless attribute_value.nil?
|
80
|
+
attribute_id = @config.get_attribute_id attribute_key
|
81
|
+
if attribute_id
|
82
|
+
visitor_attributes.push(
|
83
|
+
entity_id: attribute_id,
|
84
|
+
key: attribute_key,
|
85
|
+
type: CUSTOM_ATTRIBUTE_FEATURE_TYPE,
|
86
|
+
value: attribute_value
|
87
|
+
)
|
88
|
+
end
|
97
89
|
end
|
98
|
-
|
90
|
+
end
|
91
|
+
# Append Bot Filtering Attribute
|
92
|
+
if bot_filtering == true || bot_filtering == false
|
93
|
+
visitor_attributes.push(
|
94
|
+
entity_id: Optimizely::Helpers::Constants::CONTROL_ATTRIBUTES['BOT_FILTERING'],
|
95
|
+
key: Optimizely::Helpers::Constants::CONTROL_ATTRIBUTES['BOT_FILTERING'],
|
96
|
+
type: CUSTOM_ATTRIBUTE_FEATURE_TYPE,
|
97
|
+
value: bot_filtering
|
98
|
+
)
|
99
99
|
end
|
100
100
|
|
101
101
|
common_params = {
|
@@ -315,6 +315,12 @@ module Optimizely
|
|
315
315
|
'VARIABLE_KEY' => 'Variable key',
|
316
316
|
'VARIABLE_TYPE' => 'Variable type'
|
317
317
|
}.freeze
|
318
|
+
|
319
|
+
CONTROL_ATTRIBUTES = {
|
320
|
+
'BOT_FILTERING' => '$opt_bot_filtering',
|
321
|
+
'BUCKETING_ID' => '$opt_bucketing_id',
|
322
|
+
'USER_AGENT' => '$opt_user_agent'
|
323
|
+
}.freeze
|
318
324
|
end
|
319
325
|
end
|
320
326
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
#
|
4
|
-
# Copyright 2017, Optimizely and contributors
|
4
|
+
# Copyright 2017-2018, Optimizely and contributors
|
5
5
|
#
|
6
6
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
7
|
# you may not use this file except in compliance with the License.
|
@@ -86,20 +86,31 @@ module Optimizely
|
|
86
86
|
false
|
87
87
|
end
|
88
88
|
|
89
|
+
# @deprecated Use {#clear_notification_listeners} instead.
|
89
90
|
def clear_notifications(notification_type)
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
# notification_type: one of the constants in NOTIFICATION_TYPES
|
91
|
+
@logger.log Logger::WARN, "'clear_notifications' is deprecated. Call 'clear_notification_listeners' instead."
|
92
|
+
clear_notification_listeners(notification_type)
|
93
|
+
end
|
94
94
|
|
95
|
+
# Removes notifications for a certain notification type
|
96
|
+
#
|
97
|
+
# @param notification_type - one of the constants in NOTIFICATION_TYPES
|
98
|
+
|
99
|
+
def clear_notification_listeners(notification_type)
|
95
100
|
return nil unless notification_type_valid?(notification_type)
|
96
101
|
|
97
102
|
@notifications[notification_type] = []
|
98
103
|
@logger.log Logger::INFO, "All callbacks for notification type #{notification_type} have been removed."
|
99
104
|
end
|
100
105
|
|
106
|
+
# @deprecated Use {#clear_all_notification_listeners} instead.
|
101
107
|
def clean_all_notifications
|
102
|
-
|
108
|
+
@logger.log Logger::WARN, "'clean_all_notifications' is deprecated. Call 'clear_all_notification_listeners' instead."
|
109
|
+
clear_all_notification_listeners
|
110
|
+
end
|
111
|
+
|
112
|
+
# Removes all notifications
|
113
|
+
def clear_all_notification_listeners
|
103
114
|
@notifications.each_key { |key| @notifications[key] = [] }
|
104
115
|
end
|
105
116
|
|
@@ -15,6 +15,7 @@
|
|
15
15
|
# limitations under the License.
|
16
16
|
#
|
17
17
|
require 'json'
|
18
|
+
require_relative 'helpers/constants'
|
18
19
|
require_relative 'helpers/validator'
|
19
20
|
|
20
21
|
module Optimizely
|
@@ -25,6 +26,7 @@ module Optimizely
|
|
25
26
|
class ProjectConfig
|
26
27
|
# Representation of the Optimizely project config.
|
27
28
|
RUNNING_EXPERIMENT_STATUS = ['Running'].freeze
|
29
|
+
RESERVED_ATTRIBUTE_PREFIX = '$opt_'
|
28
30
|
|
29
31
|
# Gets project config attributes.
|
30
32
|
attr_reader :error_handler
|
@@ -41,6 +43,7 @@ module Optimizely
|
|
41
43
|
attr_reader :project_id
|
42
44
|
# Boolean - denotes if Optimizely should remove the last block of visitors' IP address before storing event data
|
43
45
|
attr_reader :anonymize_ip
|
46
|
+
attr_reader :bot_filtering
|
44
47
|
attr_reader :revision
|
45
48
|
attr_reader :rollouts
|
46
49
|
attr_reader :version
|
@@ -87,7 +90,8 @@ module Optimizely
|
|
87
90
|
@feature_flags = config.fetch('featureFlags', [])
|
88
91
|
@groups = config.fetch('groups', [])
|
89
92
|
@project_id = config['projectId']
|
90
|
-
@anonymize_ip = config.key?
|
93
|
+
@anonymize_ip = config.key?('anonymizeIP') ? config['anonymizeIP'] : false
|
94
|
+
@bot_filtering = config['botFiltering']
|
91
95
|
@revision = config['revision']
|
92
96
|
@rollouts = config.fetch('rollouts', [])
|
93
97
|
|
@@ -363,8 +367,23 @@ module Optimizely
|
|
363
367
|
end
|
364
368
|
|
365
369
|
def get_attribute_id(attribute_key)
|
370
|
+
# Get attribute ID for the provided attribute key.
|
371
|
+
#
|
372
|
+
# Args:
|
373
|
+
# Attribute key for which attribute is to be fetched.
|
374
|
+
#
|
375
|
+
# Returns:
|
376
|
+
# Attribute ID corresponding to the provided attribute key.
|
366
377
|
attribute = @attribute_key_map[attribute_key]
|
367
|
-
|
378
|
+
has_reserved_prefix = attribute_key.to_s.start_with?(RESERVED_ATTRIBUTE_PREFIX)
|
379
|
+
unless attribute.nil?
|
380
|
+
if has_reserved_prefix
|
381
|
+
@logger.log(Logger::WARN, "Attribute '#{attribute_key}' unexpectedly has reserved prefix '#{RESERVED_ATTRIBUTE_PREFIX}'; "\
|
382
|
+
'using attribute ID instead of reserved attribute name.')
|
383
|
+
end
|
384
|
+
return attribute['id']
|
385
|
+
end
|
386
|
+
return attribute_key if has_reserved_prefix
|
368
387
|
@logger.log Logger::ERROR, "Attribute key '#{attribute_key}' is not in datafile."
|
369
388
|
@error_handler.handle_error InvalidAttributeError
|
370
389
|
nil
|
data/lib/optimizely/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: optimizely-sdk
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0
|
4
|
+
version: 2.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Optimizely
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-07-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|