Class: Skadi::Configuration
- Inherits:
-
Object
- Object
- Skadi::Configuration
- Defined in:
- lib/skadi/configuration.rb
Defined Under Namespace
Classes: Error
Instance Attribute Summary collapse
-
#anonymity_set_cache_key ⇒ Object
Returns the value of attribute anonymity_set_cache_key.
-
#anonymity_set_duration ⇒ ActiveSupport::Duration
How long an anonymity set should last before expiring.
-
#anonymity_set_reset_hour ⇒ Integer, false
Set the hour of the day to reset the anonymity set.
-
#cookie_domain ⇒ String?
The domain to use when setting cookies.
-
#dashboard_custom_event_fields ⇒ Array<Hash>?
Use this to add custom fields to the events dataset in the dashboard.
-
#dashboard_custom_schema ⇒ Object
Use this to add custom database tables to the Skadi dashboard.
-
#dashboard_dangerously_use_sql_controller_method ⇒ Symbol?
Method in the host application's ApplicationController that returns true if the current request is allowed to edit raw SQL in the Skadi dashboard.
-
#dashboard_edit_controller_method ⇒ Symbol?
Method in the host application's ApplicationController that returns true if the current request is allowed to edit Skadi dashboards.
-
#dashboard_view_controller_method ⇒ Symbol?
Method in the host application's ApplicationController that returns true if the current request is allowed to view the Skadi dashboard.
-
#db_connects_to ⇒ Hash?
The database connection to use for Skadi models.
-
#max_tracking_payload_size ⇒ Integer
Sets a limit on the size of the tracking beacon.
-
#max_url_length ⇒ Integer
Maximum length of the referrer and exit page URLs.
-
#query_param_whitelist ⇒ Array<Symbol>
An array of query parameter keys to whitelist for storage in URLs.
-
#store_domain_in_views ⇒ Boolean
Whether to store the domain when tracking views.
-
#track_bots ⇒ Object
Whether to track visits by suspected bots, detected via the browser user agent.
-
#track_users ⇒ Boolean
When enabled, visits will be tracked by using the logged in user.
-
#use_anonymity_sets ⇒ Boolean
When enabled, users will automatically be tracked by their anonymity set.
-
#use_query_param_whitelist ⇒ Boolean
Enable filtering of query parameters to prevent sensitive data being exposed.
-
#user_controller_method ⇒ Symbol?
Method in the host application's ApplicationController that returns the current logged-in user.
-
#user_model ⇒ Class?
The parent app's User class, used to link visits to users.
-
#visit_duration ⇒ ActiveSupport::Duration
How long a visit should last before expiring.
Class Method Summary collapse
Instance Method Summary collapse
-
#do_not_track_bots? ⇒ Boolean
Helper method to return the inverse of :track_bots.
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
- #validate! ⇒ Object
Constructor Details
#initialize ⇒ Configuration
Returns a new instance of Configuration.
5 6 7 8 9 |
# File 'lib/skadi/configuration.rb', line 5 def initialize validators.each do |attribute, validator_configuration| send("#{attribute}=", validator_configuration[:default]) end end |
Instance Attribute Details
#anonymity_set_cache_key ⇒ Object
Returns the value of attribute anonymity_set_cache_key.
35 36 37 |
# File 'lib/skadi/configuration.rb', line 35 def anonymity_set_cache_key @anonymity_set_cache_key end |
#anonymity_set_duration ⇒ ActiveSupport::Duration
How long an anonymity set should last before expiring. Defaults to 1 day.
40 41 42 |
# File 'lib/skadi/configuration.rb', line 40 def anonymity_set_duration @anonymity_set_duration end |
#anonymity_set_reset_hour ⇒ Integer, false
Set the hour of the day to reset the anonymity set. Set to false to strictly use the set duration. Defaults to 3 (3am).
45 46 47 |
# File 'lib/skadi/configuration.rb', line 45 def anonymity_set_reset_hour @anonymity_set_reset_hour end |
#cookie_domain ⇒ String?
The domain to use when setting cookies. Set to include subdomains. Defaults to nil, which will not specify a domain when setting a cookie.
117 118 119 |
# File 'lib/skadi/configuration.rb', line 117 def @cookie_domain end |
#dashboard_custom_event_fields ⇒ Array<Hash>?
Use this to add custom fields to the events dataset in the dashboard. This should be set to a hash with values of the format:
{
label: The label to show in the front end,
type: The datatype, one of :date, :string, :number, :boolean. Defaults to :string if omitted.
filter: `true` if this field can be filtered
split: `true` if this field can be split
sql: The SQL expression used to get this value for derived fields
options: An array of possible values
description: used in the front end as help text for this field
}
For example, {type: :number, filter: true, split: true, sql: "properties->>'clicks'"} See Skadi::Schema for reference
161 162 163 |
# File 'lib/skadi/configuration.rb', line 161 def dashboard_custom_event_fields @dashboard_custom_event_fields end |
#dashboard_custom_schema ⇒ Object
Use this to add custom database tables to the Skadi dashboard. See Skadi::Schema for reference.
172 173 174 |
# File 'lib/skadi/configuration.rb', line 172 def dashboard_custom_schema @dashboard_custom_schema end |
#dashboard_dangerously_use_sql_controller_method ⇒ Symbol?
Method in the host application's ApplicationController that returns true if the current request is allowed to edit raw SQL in the Skadi dashboard. Note that exposing SQL to users is dangerous and could lead to data loss. Defaults to nil (disabled).
144 145 146 |
# File 'lib/skadi/configuration.rb', line 144 def dashboard_dangerously_use_sql_controller_method @dashboard_dangerously_use_sql_controller_method end |
#dashboard_edit_controller_method ⇒ Symbol?
Method in the host application's ApplicationController that returns true if the current request is allowed to edit Skadi dashboards. Defaults to nil (disabled).
139 140 141 |
# File 'lib/skadi/configuration.rb', line 139 def dashboard_edit_controller_method @dashboard_edit_controller_method end |
#dashboard_view_controller_method ⇒ Symbol?
Method in the host application's ApplicationController that returns true if the current request is allowed to view the Skadi dashboard. Defaults to nil (disabled).
134 135 136 |
# File 'lib/skadi/configuration.rb', line 134 def dashboard_view_controller_method @dashboard_view_controller_method end |
#db_connects_to ⇒ Hash?
The database connection to use for Skadi models
97 98 99 |
# File 'lib/skadi/configuration.rb', line 97 def db_connects_to @db_connects_to end |
#max_tracking_payload_size ⇒ Integer
Sets a limit on the size of the tracking beacon. Defaults to 1KB.
112 113 114 |
# File 'lib/skadi/configuration.rb', line 112 def max_tracking_payload_size @max_tracking_payload_size end |
#max_url_length ⇒ Integer
Maximum length of the referrer and exit page URLs. Defaults to 2048.
91 92 93 |
# File 'lib/skadi/configuration.rb', line 91 def max_url_length @max_url_length end |
#query_param_whitelist ⇒ Array<Symbol>
An array of query parameter keys to whitelist for storage in URLs.
86 87 88 |
# File 'lib/skadi/configuration.rb', line 86 def query_param_whitelist @query_param_whitelist end |
#store_domain_in_views ⇒ Boolean
Whether to store the domain when tracking views. Can be useful when using multiple domains or subdomains. Defaults to false.
107 108 109 |
# File 'lib/skadi/configuration.rb', line 107 def store_domain_in_views @store_domain_in_views end |
#track_bots ⇒ Object
Whether to track visits by suspected bots, detected via the browser user agent. Defaults to Rails.env.local? (true
for development and testing environments, and false for production/other environments).
122 123 124 |
# File 'lib/skadi/configuration.rb', line 122 def track_bots @track_bots end |
#track_users ⇒ Boolean
When enabled, visits will be tracked by using the logged in user. See the :user_model and :user_controller_method configuration options. When disabled, users will not be saved to visits without explicit consent. This option defined the default behaviour for tracking users, but the consent cookie, if it exists, will always take precedence over this configuration option. Defaults to false.
32 33 34 |
# File 'lib/skadi/configuration.rb', line 32 def track_users @track_users end |
#use_anonymity_sets ⇒ Boolean
When enabled, users will automatically be tracked by their anonymity set. An anonymity set keeps track of a user using a hash of their IP address and User Agent. A cryptographic pepper is added to the hash, which, when discarded, makes the generated token no longer able to be used to track the user. When disabled, views and events will not be linked to a visitor without explicit consent to use anonymity sets or tracking cookies. This option defined the default behaviour for using anonymity sets, but the consent cookie, if it exists, will always take precedence over this configuration option. Defaults to false.
24 25 26 |
# File 'lib/skadi/configuration.rb', line 24 def use_anonymity_sets @use_anonymity_sets end |
#use_query_param_whitelist ⇒ Boolean
Enable filtering of query parameters to prevent sensitive data being exposed. Defaults to true.
81 82 83 |
# File 'lib/skadi/configuration.rb', line 81 def use_query_param_whitelist @use_query_param_whitelist end |
#user_controller_method ⇒ Symbol?
Method in the host application's ApplicationController that returns the current logged-in user. An AR Model or nil should be returned. Used to track users; if this is nil or set to a non-existent method, user tracking is disabled. Defaults to nil (disabled).
76 77 78 |
# File 'lib/skadi/configuration.rb', line 76 def user_controller_method @user_controller_method end |
#user_model ⇒ Class?
The parent app's User class, used to link visits to users
59 60 61 |
# File 'lib/skadi/configuration.rb', line 59 def user_model @user_model end |
#visit_duration ⇒ ActiveSupport::Duration
How long a visit should last before expiring. Note: visits that cross anonymity set boundaries will be counted as two visits. Defaults to 2 hours.
54 55 56 |
# File 'lib/skadi/configuration.rb', line 54 def visit_duration @visit_duration end |
Class Method Details
.validates(attribute, expecting, default:, &block) ⇒ Object
14 15 16 |
# File 'lib/skadi/configuration.rb', line 14 def self.validates(attribute, expecting, default:, &block) validators[attribute] = { expecting: expecting, default: default, validator: block } end |
Instance Method Details
#do_not_track_bots? ⇒ Boolean
Helper method to return the inverse of :track_bots
126 |
# File 'lib/skadi/configuration.rb', line 126 def do_not_track_bots? = !@track_bots |
#validate! ⇒ Object
210 211 212 213 214 215 216 217 218 219 220 221 222 |
# File 'lib/skadi/configuration.rb', line 210 def validate! validators.each do |attribute, validator_configuration| validator = validator_configuration[:validator] expecting = validator_configuration[:expecting] value = send(attribute) if validator.call(value, self) next end error! "Skadi.configuration.#{attribute} error! Expecting a #{expecting}, but got a #{value.class}" end end |