Class: Skadi::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/skadi/configuration.rb

Defined Under Namespace

Classes: Error

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

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_keyObject

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_durationActiveSupport::Duration

How long an anonymity set should last before expiring. Defaults to 1 day.

Returns:

  • (ActiveSupport::Duration)


40
41
42
# File 'lib/skadi/configuration.rb', line 40

def anonymity_set_duration
  @anonymity_set_duration
end

#anonymity_set_reset_hourInteger, 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).

Returns:

  • (Integer, false)


45
46
47
# File 'lib/skadi/configuration.rb', line 45

def anonymity_set_reset_hour
  @anonymity_set_reset_hour
end

The domain to use when setting cookies. Set to include subdomains. Defaults to nil, which will not specify a domain when setting a cookie.

Returns:

  • (String, nil)


117
118
119
# File 'lib/skadi/configuration.rb', line 117

def cookie_domain
  @cookie_domain
end

#dashboard_custom_event_fieldsArray<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

Returns:

  • (Array<Hash>, nil)


161
162
163
# File 'lib/skadi/configuration.rb', line 161

def dashboard_custom_event_fields
  @dashboard_custom_event_fields
end

#dashboard_custom_schemaObject

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_methodSymbol?

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).

Returns:

  • (Symbol, nil)


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_methodSymbol?

Method in the host application's ApplicationController that returns true if the current request is allowed to edit Skadi dashboards. Defaults to nil (disabled).

Returns:

  • (Symbol, nil)


139
140
141
# File 'lib/skadi/configuration.rb', line 139

def dashboard_edit_controller_method
  @dashboard_edit_controller_method
end

#dashboard_view_controller_methodSymbol?

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).

Returns:

  • (Symbol, nil)


134
135
136
# File 'lib/skadi/configuration.rb', line 134

def dashboard_view_controller_method
  @dashboard_view_controller_method
end

#db_connects_toHash?

The database connection to use for Skadi models

Returns:

  • (Hash, nil)

See Also:

  • ActiveRecord::ConnectionHandling.connects_to


97
98
99
# File 'lib/skadi/configuration.rb', line 97

def db_connects_to
  @db_connects_to
end

#max_tracking_payload_sizeInteger

Sets a limit on the size of the tracking beacon. Defaults to 1KB.

Returns:

  • (Integer)


112
113
114
# File 'lib/skadi/configuration.rb', line 112

def max_tracking_payload_size
  @max_tracking_payload_size
end

#max_url_lengthInteger

Maximum length of the referrer and exit page URLs. Defaults to 2048.

Returns:

  • (Integer)


91
92
93
# File 'lib/skadi/configuration.rb', line 91

def max_url_length
  @max_url_length
end

#query_param_whitelistArray<Symbol>

An array of query parameter keys to whitelist for storage in URLs.

Returns:

  • (Array<Symbol>)


86
87
88
# File 'lib/skadi/configuration.rb', line 86

def query_param_whitelist
  @query_param_whitelist
end

#store_domain_in_viewsBoolean

Whether to store the domain when tracking views. Can be useful when using multiple domains or subdomains. Defaults to false.

Returns:

  • (Boolean)


107
108
109
# File 'lib/skadi/configuration.rb', line 107

def store_domain_in_views
  @store_domain_in_views
end

#track_botsObject

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_usersBoolean

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.

Returns:

  • (Boolean)


32
33
34
# File 'lib/skadi/configuration.rb', line 32

def track_users
  @track_users
end

#use_anonymity_setsBoolean

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.

Returns:

  • (Boolean)


24
25
26
# File 'lib/skadi/configuration.rb', line 24

def use_anonymity_sets
  @use_anonymity_sets
end

#use_query_param_whitelistBoolean

Enable filtering of query parameters to prevent sensitive data being exposed. Defaults to true.

Returns:

  • (Boolean)


81
82
83
# File 'lib/skadi/configuration.rb', line 81

def use_query_param_whitelist
  @use_query_param_whitelist
end

#user_controller_methodSymbol?

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).

Returns:

  • (Symbol, nil)


76
77
78
# File 'lib/skadi/configuration.rb', line 76

def user_controller_method
  @user_controller_method
end

#user_modelClass?

The parent app's User class, used to link visits to users

Returns:

  • (Class, nil)


59
60
61
# File 'lib/skadi/configuration.rb', line 59

def user_model
  @user_model
end

#visit_durationActiveSupport::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.

Returns:

  • (ActiveSupport::Duration)


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

Returns:

  • (Boolean)


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