Class: Flagsmith::AnalyticsProcessor
- Inherits:
-
Object
- Object
- Flagsmith::AnalyticsProcessor
- Defined in:
- lib/flagsmith/sdk/analytics_processor.rb
Overview
Used to control how often we send data(in seconds)
Constant Summary collapse
- ENDPOINT =
'analytics/flags/'- TIMER =
10
Instance Attribute Summary collapse
-
#analytics_data ⇒ Object
readonly
Returns the value of attribute analytics_data.
-
#last_flushed ⇒ Object
readonly
Returns the value of attribute last_flushed.
-
#timeout ⇒ Object
readonly
Returns the value of attribute timeout.
Instance Method Summary collapse
-
#flush ⇒ Object
Sends all the collected data to the api asynchronously and resets the timer.
-
#initialize(data) ⇒ AnalyticsProcessor
constructor
AnalyticsProcessor is used to track how often individual Flags are evaluated within the Flagsmith SDK.
- #track_feature(feature_id) ⇒ Object
Constructor Details
#initialize(data) ⇒ AnalyticsProcessor
AnalyticsProcessor is used to track how often individual Flags are evaluated within the Flagsmith SDK. Docs: docs.flagsmith.com/advanced-use/flag-analytics.
data environment key obtained from the Flagsmith UI data base api url to override when using self hosted version data used to tell requests to stop waiting for a response after a
given number of seconds
17 18 19 20 21 22 |
# File 'lib/flagsmith/sdk/analytics_processor.rb', line 17 def initialize(data) @last_flushed = Time.now @analytics_data = {} @api_client = data.fetch(:api_client) @timeout = data.fetch(:timeout, 3) end |
Instance Attribute Details
#analytics_data ⇒ Object (readonly)
Returns the value of attribute analytics_data.
8 9 10 |
# File 'lib/flagsmith/sdk/analytics_processor.rb', line 8 def analytics_data @analytics_data end |
#last_flushed ⇒ Object (readonly)
Returns the value of attribute last_flushed.
8 9 10 |
# File 'lib/flagsmith/sdk/analytics_processor.rb', line 8 def last_flushed @last_flushed end |
#timeout ⇒ Object (readonly)
Returns the value of attribute timeout.
8 9 10 |
# File 'lib/flagsmith/sdk/analytics_processor.rb', line 8 def timeout @timeout end |
Instance Method Details
#flush ⇒ Object
Sends all the collected data to the api asynchronously and resets the timer
25 26 27 28 29 30 31 32 |
# File 'lib/flagsmith/sdk/analytics_processor.rb', line 25 def flush return if @analytics_data.empty? @api_client.post(ENDPOINT, @analytics_data.to_json) @analytics_data = {} @last_flushed = Time.now end |
#track_feature(feature_id) ⇒ Object
34 35 36 37 |
# File 'lib/flagsmith/sdk/analytics_processor.rb', line 34 def track_feature(feature_id) @analytics_data[feature_id] = @analytics_data.fetch(feature_id, 0) + 1 flush if (Time.now - @last_flushed) > TIMER * 1000 end |