Skip to content

Commit a1e6b6f

Browse files
oakbanimauerbac
authored andcommitted
Feature - IP Anonymization (#67)
* 🖊️ anonymizeIp parsed in project_config.rb 🖊️ Param added in commonparams in event_builder.rb 🖊️ Unit test cases updated in event_builder_spec.rb and project_spec.rb * 🖊️ Modified param/method name * ✏️Set anonymize ip to false by default if not defined in data file * indent
1 parent 9f5a688 commit a1e6b6f

File tree

5 files changed

+14
-4
lines changed

5 files changed

+14
-4
lines changed

lib/optimizely/event_builder.rb

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,11 @@ def get_common_params(user_id, attributes)
9393
snapshots: [],
9494
visitor_id: user_id
9595
}
96-
],
97-
revision: @config.revision,
98-
client_name: CLIENT_ENGINE,
99-
client_version: VERSION
96+
],
97+
anonymize_ip: @config.anonymize_ip,
98+
revision: @config.revision,
99+
client_name: CLIENT_ENGINE,
100+
client_version: VERSION
100101
}
101102

102103
common_params

lib/optimizely/project_config.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ class ProjectConfig
3838
attr_reader :groups
3939
attr_reader :parsing_succeeded
4040
attr_reader :project_id
41+
# Boolean - denotes if Optimizely should remove the last block of visitors' IP address before storing event data
42+
attr_reader :anonymize_ip
4143
attr_reader :revision
4244
attr_reader :rollouts
4345
attr_reader :version
@@ -86,6 +88,7 @@ def initialize(datafile, logger, error_handler)
8688
@feature_flags = config.fetch('featureFlags', [])
8789
@groups = config.fetch('groups', [])
8890
@project_id = config['projectId']
91+
@anonymize_ip = (config.has_key? 'anonymizeIP')? config['anonymizeIP'] :false
8992
@revision = config['revision']
9093
@rollouts = config.fetch('rollouts', [])
9194

spec/event_builder_spec.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
}]
5858
}]
5959
}],
60+
anonymize_ip: false,
6061
revision: '42',
6162
client_name: Optimizely::CLIENT_ENGINE,
6263
client_version: Optimizely::VERSION
@@ -81,6 +82,7 @@
8182
}]
8283
}]
8384
}],
85+
anonymize_ip: false,
8486
revision: '42',
8587
client_name: Optimizely::CLIENT_ENGINE,
8688
client_version: Optimizely::VERSION

spec/project_spec.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ class InvalidErrorHandler; end
142142
}],
143143
visitor_id: 'test_user'
144144
}],
145+
anonymize_ip: false,
145146
revision: '42',
146147
client_name: Optimizely::CLIENT_ENGINE,
147148
client_version: Optimizely::VERSION
@@ -345,6 +346,7 @@ class InvalidErrorHandler; end
345346
}],
346347
visitor_id: 'test_user'
347348
}],
349+
anonymize_ip: false,
348350
revision: '42',
349351
client_name: Optimizely::CLIENT_ENGINE,
350352
client_version: Optimizely::VERSION
@@ -599,6 +601,7 @@ class InvalidErrorHandler; end
599601
}],
600602
visitor_id: 'test_user'
601603
}],
604+
anonymize_ip: false,
602605
revision: '42',
603606
client_name: Optimizely::CLIENT_ENGINE,
604607
client_version: Optimizely::VERSION

spec/spec_params.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ module OptimizelySpec
1919
VALID_CONFIG_BODY = {
2020
'accountId' => '12001',
2121
'projectId' => '111001',
22+
'anonymizeIP'=> false,
2223
'revision' => '42',
2324
'version' => '2',
2425
'events' => [{

0 commit comments

Comments
 (0)