skadi 0.4.0.beta.5 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +26 -0
- data/README.md +387 -21
- data/app/assets/builds/dashboard.css +1 -1
- data/app/assets/builds/dashboard.js +3 -3
- data/app/assets/builds/skadi.js +1 -1
- data/app/assets/builds/skadiVisit.js +1 -0
- data/app/controllers/skadi/asset_controller.rb +4 -0
- data/app/controllers/skadi/dashboard_controller.rb +77 -15
- data/app/controllers/skadi/tracking_controller.rb +22 -19
- data/app/helpers/skadi/application_helper.rb +46 -17
- data/app/models/skadi/application_record.rb +2 -0
- data/app/models/skadi/dashboard.rb +12 -0
- data/app/models/skadi/dashboard_query.rb +17 -5
- data/app/models/skadi/dashboard_record.rb +10 -0
- data/app/models/skadi/dashboard_validator.rb +7 -5
- data/app/models/skadi/schema.rb +1 -1
- data/app/models/skadi/visit.rb +3 -5
- data/app/views/skadi/dashboard/index.html.erb +33 -0
- data/app/views/skadi/dashboard/show.html.erb +15 -5
- data/config/routes.rb +7 -4
- data/lib/generators/skadi/install/templates/skadi_initializer.rb +10 -0
- data/lib/generators/skadi/install/templates/skadi_migration.rb.erb +5 -0
- data/lib/skadi/configuration.rb +26 -9
- data/lib/skadi/controller_delegate.rb +39 -25
- data/lib/skadi/engine.rb +29 -6
- data/lib/skadi/version.rb +1 -1
- metadata +57 -12
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 519c8d96cd9985887f986f236fda02168a1e4b43b19de14e01ab00c2823a04c1
|
|
4
|
+
data.tar.gz: dbbd25a2e208519c78007c7be828c618fb233fbc901e2a1f1ef7f046aa3e2cb5
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 21caad46cfc18647a08414ffd99df67a05edb31523745980c438708d3f5e69be7bfee9dc9b93e5b2eae04946e4ee3f01334df2fdddb9731584686ebca9662445
|
|
7
|
+
data.tar.gz: b2bf6cd683d4abc2a9898d5e0175926bb174179b2d3dd5942683cdf37bd5b314c5758968e251282a09deb8056c479db81125f9839bec401b5451d08d3ea964d3
|
data/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,29 @@
|
|
|
1
|
+
## 1.0.0 [2026-12-04]
|
|
2
|
+
- Add multiple dashboards: `/skadi` lists the dashboards, and users with edit permission can create, rename, describe and delete them
|
|
3
|
+
- Reject dashboard saves based on an outdated version, so editors can't overwrite each other's changes. Saves are now debounced and sent one at a time.
|
|
4
|
+
- Add `dashboard_database` configuration option to run dashboard queries on a separate (e.g. read-only) connection
|
|
5
|
+
- Add `dashboard_forbidden_method` configuration option, e.g. to redirect forbidden users to a login page
|
|
6
|
+
- Add `tracking_rate_limit` and `tracking_rate_limit_period` configuration options, and raise the default rate limit to 200 requests per minute
|
|
7
|
+
- Add `ControllerDelegate#consent` to match the frontend API
|
|
8
|
+
- Allow consent to be updated on pages without a tracked view, including `do_not_track` pages
|
|
9
|
+
- Fix user consent not applying immediately
|
|
10
|
+
- Fix dashboard visit datasets not including visits with users
|
|
11
|
+
- Fix dashboard validator crashing on some malformed configurations
|
|
12
|
+
- Fix model configuration resetting when code is reloaded (e.g. in development)
|
|
13
|
+
- Remove `(.:format)` from tracked URIs
|
|
14
|
+
- Tracking script: split into separate view and visit scripts, with the visit script only loaded for new visits
|
|
15
|
+
- Tracking script: fix loading with Turbo
|
|
16
|
+
- Tracking script: read tag data from a meta tag
|
|
17
|
+
- Tracking script: fix beacons being sent on `do_not_track` pages
|
|
18
|
+
- Tracking script: ignore non-boolean values passed to `skadi.consent`
|
|
19
|
+
- Tracking script: round timings up to the next 100ms
|
|
20
|
+
- Tracking script: add the sensitive event parameter
|
|
21
|
+
- Development: add system tests
|
|
22
|
+
- Development: remove the appraisal gem and rework the testall script
|
|
23
|
+
|
|
24
|
+
## 0.4.0.beta.6 [2026-09-29]
|
|
25
|
+
- Remove restrictions on SQL for table datasets
|
|
26
|
+
|
|
1
27
|
## 0.4.0.beta.5 [2026-09-21]
|
|
2
28
|
- Fix inconsistent ordering of SQL datasets
|
|
3
29
|
- Add CI
|
data/README.md
CHANGED
|
@@ -11,12 +11,14 @@ _* See [compliance section](#compliance)_
|
|
|
11
11
|
> [!NOTE]
|
|
12
12
|
> This is a human-written project with limited AI assistance. See the [AI Disclaimer](#ai-disclaimer) for details.
|
|
13
13
|
|
|
14
|
+
|
|
14
15
|
## Dependencies
|
|
15
16
|
|
|
16
17
|
This gem requires Rails >= 7.2 and Ruby >= 3.3.
|
|
17
18
|
|
|
18
19
|
This gem has no dependencies on other packages when installed as a gem.
|
|
19
20
|
|
|
21
|
+
|
|
20
22
|
## Quick start
|
|
21
23
|
|
|
22
24
|
Install the gem:
|
|
@@ -25,7 +27,7 @@ Install the gem:
|
|
|
25
27
|
bundle add skadi
|
|
26
28
|
```
|
|
27
29
|
|
|
28
|
-
Generate and run the database migration:
|
|
30
|
+
Generate and run the Skadi initialiser and database migration:
|
|
29
31
|
|
|
30
32
|
```shell
|
|
31
33
|
rails generate skadi:install
|
|
@@ -40,45 +42,131 @@ class ApplicationController
|
|
|
40
42
|
end
|
|
41
43
|
```
|
|
42
44
|
|
|
45
|
+
Add Skadi to your routes:
|
|
46
|
+
|
|
47
|
+
```ruby
|
|
48
|
+
mount Skadi::Engine => "/skadi"
|
|
49
|
+
```
|
|
50
|
+
|
|
43
51
|
Add the Skadi tracking tag to your layout:
|
|
44
52
|
|
|
45
53
|
```erb
|
|
46
54
|
<%= skadi_tag %>
|
|
47
55
|
```
|
|
48
56
|
|
|
57
|
+
All controller actions will now be automatically tracked and verified. Start tracking your own data and consent from the front end or your controllers:
|
|
58
|
+
|
|
59
|
+
```ruby
|
|
60
|
+
# Inside a Rails controller:
|
|
61
|
+
def show
|
|
62
|
+
# Record events with arbitrary data
|
|
63
|
+
skadi.event("event name", {some: "property"})
|
|
64
|
+
|
|
65
|
+
# Record counts of sensitive data in aggregated buckets, not linked to other data
|
|
66
|
+
skadi.demographic("nationality", "British")
|
|
67
|
+
|
|
68
|
+
# Enable/disable tracking sessions using cookies
|
|
69
|
+
skadi.cookie_consent!(true)
|
|
70
|
+
|
|
71
|
+
# Enable/disable tracking sessions by anonymity sets (a daily hash of IP/User Agent)
|
|
72
|
+
skadi.anonymity_set_consent!(false)
|
|
73
|
+
|
|
74
|
+
# Enable/disable tracking sessions by user id
|
|
75
|
+
skadi.user_consent!(true)
|
|
76
|
+
end
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
```javascript
|
|
80
|
+
// Or on the front end:
|
|
81
|
+
window.skadi.event("event name", {some: "property"})
|
|
82
|
+
window.skadi.demographic("nationality", "British")
|
|
83
|
+
|
|
84
|
+
// Consent is only changed if the key/value pair is specified in the hash
|
|
85
|
+
window.skadi.consent({
|
|
86
|
+
cookie: true,
|
|
87
|
+
anonymity_set: false,
|
|
88
|
+
user: true,
|
|
89
|
+
})
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
To explore the data, enable the [dashboard](#dashboard). For more customisation, see the generated `config/initializers/skadi.rb` file ([source](lib/generators/skadi/install/templates/skadi_initializer.rb)).
|
|
93
|
+
|
|
94
|
+
|
|
49
95
|
## AI Disclaimer
|
|
50
96
|
|
|
51
|
-
This gem is human-written, with AI used improve the quality of the code, corresponding to [level 3 to 4](https://www.visidata.org/blog/2026/ai/#self-assessed-ai-level-for-contributions) on the VisiData AI scale
|
|
97
|
+
This gem is primarily human-written, with AI used to improve the quality of the code, corresponding to [level 3 to 4](https://www.visidata.org/blog/2026/ai/#self-assessed-ai-level-for-contributions) on the VisiData AI scale. Limited AI code generation is also used, corresponding to level 5; for example, to write boilerplate or test code which is then refactored by hand.
|
|
52
98
|
|
|
53
99
|
> **Level 3**: Human coded, bots assisted non-trivially
|
|
54
|
-
> **Level 4**: Human coded, bots helped significantly
|
|
100
|
+
> **Level 4**: Human coded, bots helped significantly
|
|
101
|
+
> **Level 5**: Bots coded, human understands completely
|
|
102
|
+
|
|
103
|
+
AI is used for same-line autocomplete suggestions, research, code review and limited code generation. Humans make all the architectural decisions, and review and take responsibility for all resulting code.
|
|
55
104
|
|
|
56
|
-
AI was used for same-line autocomplete suggestions, research and code review. Humans made all the architectural decisions, logic and the resulting code.
|
|
57
105
|
|
|
58
106
|
## Why use Skadi?
|
|
59
107
|
|
|
60
|
-
|
|
61
|
-
|
|
108
|
+
Skadi is **first party**. The data that you collect is stored on your servers and never sent to third parties.
|
|
109
|
+
|
|
110
|
+
Skadi is **privacy focused**. It was built to ensure that your users' privacy is respected.
|
|
111
|
+
|
|
112
|
+
Skadi has **cookie tracking opt-in**. Tracking cookies are only set once a user consents, so you still get accurate return-visit data from those who opt in.
|
|
113
|
+
|
|
114
|
+
Skadi provides a **data dashboard**. Explore and share your website's analytics data without third party tools.
|
|
115
|
+
|
|
116
|
+
Additionally, the Skadi gem's only dependency is Rails, and makes no assumptions about how your app bundles assets.
|
|
117
|
+
|
|
118
|
+
| | Skadi | Ahoy | Plausible | GA |
|
|
119
|
+
|------------------------|-------|---------------------|----------------|-----|
|
|
120
|
+
| First party | Yes | Yes | No | No |
|
|
121
|
+
| Privacy focused | Yes | Partial<sup>1</sup> | Yes | No |
|
|
122
|
+
| Cookie tracking opt-in | Yes | No<sup>2</sup> | No<sup>3</sup> | Yes |
|
|
123
|
+
| Data dashboard | Yes | No | Yes | Yes |
|
|
124
|
+
|
|
125
|
+
<sup>1</sup>Ahoy in cookieless mode derives a visitor token from a [hash of IP address and user agent](https://github.com/ankane/ahoy/blob/f441707688dfde0ac77ae2494982926cebcec7c8/lib/ahoy/tracker.rb#L251), with no salt and no rotation, so visitors can be linked indefinitely. This may not be compliant with some privacy laws.<br>
|
|
126
|
+
<sup>2</sup>Ahoy has no built-in per-user consent mechanism.<br>
|
|
127
|
+
<sup>3</sup>Plausible is cookieless by design and has no option to set tracking cookies.
|
|
128
|
+
|
|
129
|
+
Last updated October 2026.
|
|
62
130
|
|
|
63
131
|
|
|
64
132
|
## Compliance
|
|
65
133
|
|
|
66
|
-
Skadi respects users' privacy without any additional configuration. This means that Skadi will not store any personal data or track individual users without explicit consent.
|
|
134
|
+
Skadi respects users' privacy without any additional configuration. This means that Skadi, by default, will not store any personal data or track individual users without explicit consent.
|
|
67
135
|
|
|
68
136
|
> [!NOTE]
|
|
69
137
|
> It is your responsibility to comply with any applicable privacy laws. Skadi does not provide any legal advice as to the compliance of your use of Skadi.
|
|
70
138
|
|
|
71
|
-
### Cookies
|
|
72
139
|
|
|
73
|
-
|
|
140
|
+
### Cookie tracking
|
|
74
141
|
|
|
75
|
-
The
|
|
142
|
+
The __skadi_id__ analytics cookie is used to store a unique identifier for a user. This identifier is used to track the user across multiple visits to the site. This cookie is only set after the user provides consent:
|
|
76
143
|
|
|
77
|
-
|
|
144
|
+
```ruby
|
|
145
|
+
# In a controller action
|
|
146
|
+
skadi.cookie_consent!(true)
|
|
147
|
+
```
|
|
148
|
+
```javascript
|
|
149
|
+
// On the front end
|
|
150
|
+
window.skadi.consent({cookie: true})
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
When a user withdraws consent for cookies, the tracking token is discarded and all existing data can no longer be linked to that user. The user's current visit is converted into an anonymity set, if anonymity set tracking is enabled for them.
|
|
154
|
+
|
|
155
|
+
```ruby
|
|
156
|
+
# In a controller action
|
|
157
|
+
skadi.cookie_consent!(false)
|
|
158
|
+
```
|
|
159
|
+
```javascript
|
|
160
|
+
// On the front end
|
|
161
|
+
window.skadi.consent({cookie: false})
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
### Anonymity set tracking
|
|
78
166
|
|
|
79
167
|
Some DPAs provide exceptions that allow for limited tracking of users before they consent, provided that the data is aggregated within a short time-frame. For example, the [Statistical Purposes exception](https://ico.org.uk/for-organisations/direct-marketing-and-privacy-and-electronic-communications/guidance-on-the-use-of-storage-and-access-technologies/what-are-the-exceptions/#statistical) for the UK GDPR.
|
|
80
168
|
|
|
81
|
-
Skadi allows
|
|
169
|
+
Skadi allows the use of pseudonymous "anonymity sets" that can track a user's visit across multiple pages throughout a day. These are disabled by default, but you can enable them for all users by configuration; users are still able to opt out using the consent API.
|
|
82
170
|
|
|
83
171
|
```ruby
|
|
84
172
|
Skadi.configure do |config|
|
|
@@ -86,26 +174,304 @@ Skadi.configure do |config|
|
|
|
86
174
|
end
|
|
87
175
|
```
|
|
88
176
|
|
|
89
|
-
This anonymity set is calculated using a hash of the User's IP Address, their User Agent
|
|
177
|
+
This anonymity set is calculated using a hash of the User's IP Address, their User Agent and a random value called a pepper.
|
|
90
178
|
|
|
91
179
|
```
|
|
92
180
|
anonymity_set = hash(ip_address + user_agent + pepper)
|
|
93
181
|
```
|
|
94
182
|
|
|
95
|
-
Although the resulting
|
|
183
|
+
Although the resulting token contains no personal information, it can still be used to track users, so it is considered pseudonymous rather than truly anonymous, and thus still subject to privacy laws. Once the pepper has been discarded, the anonymity set can no longer be used to identify an individual; the pepper is rotated and discarded daily, making the data collected fully anonymous after a day; the lifetime and reset hour of the pepper can be changed by [configuration](lib/skadi/configuration.rb).
|
|
184
|
+
|
|
185
|
+
Some privacy laws (e.g. [the UK ICO's 'simple and free' means to object]) also require that users be given the option to opt-out of anonymisation-set tracking:
|
|
186
|
+
|
|
187
|
+
```ruby
|
|
188
|
+
# In a controller action
|
|
189
|
+
skadi.anonymity_set_consent!(false)
|
|
190
|
+
```
|
|
191
|
+
```javascript
|
|
192
|
+
// On the front end
|
|
193
|
+
window.skadi.consent({anonymity_set: false})
|
|
194
|
+
```
|
|
195
|
+
|
|
196
|
+
This will remove the anonymity set token from the database for the current and previous visits, and will set the necessary `skadi_anonymity_set` cookie to keep track of the user's consent.
|
|
197
|
+
|
|
198
|
+
Skadi will still collect view, event and demographic data for these users, but they will not be linked to an individual, and no personal information will be stored.
|
|
199
|
+
|
|
200
|
+
|
|
201
|
+
### User tracking
|
|
202
|
+
|
|
203
|
+
Skadi can be configured to track visits using the logged-in user's ID. The user's visits will be linked to the user model once consent has been granted:
|
|
204
|
+
|
|
205
|
+
```ruby
|
|
206
|
+
# In a controller action
|
|
207
|
+
skadi.user_consent!(true)
|
|
208
|
+
```
|
|
209
|
+
```javascript
|
|
210
|
+
// On the front end
|
|
211
|
+
window.skadi.consent({user: true})
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
When the `track_users` configuration option is enabled, Skadi will automatically start tracking visits using the user's ID. You should only enable this if you already have consent to track _all users_.
|
|
215
|
+
|
|
216
|
+
```ruby
|
|
217
|
+
Skadi.configure do |config|
|
|
218
|
+
config.track_users = true
|
|
219
|
+
end
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
User tracking consent can be revoked, even when `track_users` is enabled. On revocation, the current user's id is removed from the current visit and all existing visits in the database:
|
|
223
|
+
|
|
224
|
+
```ruby
|
|
225
|
+
# In a controller action
|
|
226
|
+
skadi.user_consent!(false)
|
|
227
|
+
```
|
|
228
|
+
```javascript
|
|
229
|
+
// On the front end
|
|
230
|
+
window.skadi.consent({user: false})
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
The user's consent is stored in the necessary `skadi_track_user` cookie.
|
|
234
|
+
|
|
235
|
+
|
|
236
|
+
### Cookie summary
|
|
237
|
+
|
|
238
|
+
Skadi sets the following cookies. Each has a lifetime of one year, renewed on each visit.
|
|
239
|
+
|
|
240
|
+
| Cookie | Value | Type | Description |
|
|
241
|
+
|---------------------|--------|-----------|---------------------------------------------------------------------------------------------------------------------------------------------------------|
|
|
242
|
+
| skadi_id | uuid | Analytics | Set to a unique UUID when the user consents to cookie tracking. If omitted, their preference is assumed to be not tracked by cookies. |
|
|
243
|
+
| skadi_anonymity_set | 1 or 0 | Necessary | Stores the user's consent preference to track them by anonymity set. If omitted, their preference defaults to `Skadi.configuration.use_anonymity_sets`. |
|
|
244
|
+
| skadi_track_user | 1 or 0 | Necessary | Stores the user's consent preference to track them by their user id. If omitted, their preference defaults to `Skadi.configuration.track_users`. |
|
|
245
|
+
|
|
246
|
+
|
|
247
|
+
## API
|
|
248
|
+
|
|
249
|
+
### skadi.visit
|
|
250
|
+
|
|
251
|
+
In a controller, `skadi.visit` accesses the current visit model. `skadi.new_visit?` is true when the visit has been created in the current request. Note that `skadi.visit` can sometimes be `nil` if there is no tracking method, no UTM parameters and no external referrer.
|
|
252
|
+
|
|
253
|
+
#### Visit schema
|
|
254
|
+
|
|
255
|
+
| Field | Type | Description |
|
|
256
|
+
|-------------------------------------------------------------------------|-------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
|
257
|
+
| visit_token | uuid | A unique UUID for this visit, sent to the frontend to identify this visit. |
|
|
258
|
+
| tracking_token | uuid | A UUID tracking the user across multiple visits: if cookies_enabled is true, then this will be the token stored in the user's cookie. Otherwise, it will either be the anonymity set UUID or NULL if the user isn't tracked across multiple visits. |
|
|
259
|
+
| user_id | foreign key | The ID of the authenticated user, if they have consented. |
|
|
260
|
+
| referrer | string | The HTTP_REFERER of the user's first request. Note that URL parameters are removed unless whitelisted. |
|
|
261
|
+
| landing_page | string | The URL of the first page the user lands on. |
|
|
262
|
+
| utm_source<br/>utm_medium<br/>utm_term<br/>utm_content<br/>utm_campaign | string | The UTM query parameters sent on the user's first request. |
|
|
263
|
+
| verified | boolean | Whether at least one view has been verified (that is, a second factor beacon from the frontend has been received). |
|
|
264
|
+
| cookies_enabled | boolean | Whether the user has consented to cookie tracking. |
|
|
265
|
+
|
|
266
|
+
|
|
267
|
+
|
|
268
|
+
### skadi.view
|
|
269
|
+
|
|
270
|
+
In a controller, `skadi.view` accesses the current view model. Unlike visits, `skadi.view` will always return a model unless tracking is disabled for the action. Any changes you make to the view will be saved after the action completes.
|
|
271
|
+
|
|
272
|
+
When performing A/B testing, the version of the view can be set in the controller:
|
|
273
|
+
|
|
274
|
+
```ruby
|
|
275
|
+
# In a controller action
|
|
276
|
+
skadi.view.version = "A"
|
|
277
|
+
```
|
|
278
|
+
|
|
279
|
+
If the current view's path has sensitive information, e.g. a password reset link with a token, the path can be overwritten. This redacts the view only; the visit's `landing_page` and view's `exit_page` can still contain the full path.
|
|
280
|
+
|
|
281
|
+
```ruby
|
|
282
|
+
# In a controller action
|
|
283
|
+
skadi.view.path = "/password-reset/<redacted>"
|
|
284
|
+
```
|
|
285
|
+
|
|
286
|
+
#### View schema
|
|
287
|
+
|
|
288
|
+
| Field | Type | Description |
|
|
289
|
+
|--------------|-------------|---------------------------------------------------------------------------------------------------------------------------------------------|
|
|
290
|
+
| visit_id | foreign key | The visit this view is linked to. |
|
|
291
|
+
| view_token | string | A unique UUID for this view, sent to the frontend to identify this view. |
|
|
292
|
+
| controller | string | The name of the controller processing the request. |
|
|
293
|
+
| action | string | The name of the action in the controller. |
|
|
294
|
+
| verb | string | The HTTP verb of the request (GET, POST, etc.). |
|
|
295
|
+
| path | string | The request's path. Always starts with a leading slash unless `Skadi.configuration.store_domain_in_views` is enabled. |
|
|
296
|
+
| query_params | json | The query parameters passed with the request. Note that this is passed through the query parameter whitelist, if enabled. |
|
|
297
|
+
| exit_page | string | The last link the user clicked on in the page. |
|
|
298
|
+
| verified | boolean | Whether Skadi has received a confirmation from the frontend for this view. This can help rule out some views from bots or prefetched links. |
|
|
299
|
+
| version | string | Placeholder for a version string for the view, which can be used for A/B testing. |
|
|
300
|
+
|
|
301
|
+
|
|
302
|
+
### skadi.event
|
|
303
|
+
|
|
304
|
+
Creates a new event and optionally links it to the current view and visit.
|
|
305
|
+
|
|
306
|
+
```ruby
|
|
307
|
+
# In a controller action
|
|
308
|
+
skadi.event(name, properties = {}, sensitive: false)
|
|
309
|
+
```
|
|
310
|
+
```javascript
|
|
311
|
+
// On the front end
|
|
312
|
+
window.skadi.event(name, properties = {}, sensitive = false)
|
|
313
|
+
```
|
|
314
|
+
|
|
315
|
+
| Parameter | Type | Description |
|
|
316
|
+
|------------|---------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
|
317
|
+
| name | string | The name of the event. |
|
|
318
|
+
| properties | hash | Optional. A string-keyed hash containing arbitrary data to be linked with the event. |
|
|
319
|
+
| sensitive | boolean | Optional. Whether the event contains sensitive data. Events marked as sensitive will not be linked to a view or visit, and their created at timestamp will be set to the start of the day. |
|
|
320
|
+
|
|
321
|
+
#### Event schema
|
|
322
|
+
|
|
323
|
+
| Field | Type | Description |
|
|
324
|
+
|------------|-------------|--------------------------------------------------------------------------------|
|
|
325
|
+
| visit_id | foreign key | The visit this event is linked to. Null if this event was marked as sensitive. |
|
|
326
|
+
| view_id | foreign key | The view this event is linked to. Null if this event was marked as sensitive. |
|
|
327
|
+
| name | string | The name given to the event |
|
|
328
|
+
| properties | json | Additional data attached to the event |
|
|
329
|
+
|
|
330
|
+
|
|
331
|
+
### skadi.demographic
|
|
332
|
+
|
|
333
|
+
Increments a demographic bucket for a given name and value.
|
|
334
|
+
|
|
335
|
+
```ruby
|
|
336
|
+
# In a controller action
|
|
337
|
+
skadi.demographic(name, value, action_specific: false)
|
|
338
|
+
```
|
|
339
|
+
```javascript
|
|
340
|
+
// On the front end
|
|
341
|
+
window.skadi.demographic(name, value, actionSpecific = false)
|
|
342
|
+
```
|
|
343
|
+
|
|
344
|
+
| Parameter | Type | Description |
|
|
345
|
+
|-----------------|---------|--------------------------------------------------------------------------------------------------------------------------------------|
|
|
346
|
+
| name | string | The name of the demographic. |
|
|
347
|
+
| value | string | The value bucket for the demographic. |
|
|
348
|
+
| action_specific | boolean | Optional. Whether the demographic should be scoped to the current action, e.g. FCP for a page, or unscoped, e.g. the user's browser. |
|
|
349
|
+
|
|
350
|
+
#### Demographic schema
|
|
351
|
+
|
|
352
|
+
| Field | Type | Description |
|
|
353
|
+
|-------------|---------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
|
354
|
+
| uri | string | The URI of the page this demographic is for. If an empty string, this demographic is global and not linked to a page. Uses Rails' `request.route_uri_pattern` method. |
|
|
355
|
+
| name | string | The name of the demographic. |
|
|
356
|
+
| value | string | The value bucket for the demographic. |
|
|
357
|
+
| recorded_on | date | The date this demographic was created or incremented on. |
|
|
358
|
+
| count | integer | The number of times this name and value was seen. |
|
|
359
|
+
|
|
360
|
+
|
|
361
|
+
### skadi.consent
|
|
362
|
+
|
|
363
|
+
Sets the consent preferences for the user.
|
|
364
|
+
|
|
365
|
+
```ruby
|
|
366
|
+
# In a controller action
|
|
367
|
+
skadi.consent(cookie: true, anonymity_set: false, user: true)
|
|
368
|
+
```
|
|
369
|
+
```javascript
|
|
370
|
+
// On the front end
|
|
371
|
+
window.skadi.consent({cookie: true, anonymity_set: false, user: true})
|
|
372
|
+
```
|
|
373
|
+
|
|
374
|
+
| Parameter | Type | Description |
|
|
375
|
+
|---------------|---------|--------------------------------------------------------------------------------------------------------------------------------------------|
|
|
376
|
+
| anonymity_set | boolean | Optional. Sets the user's preference for tracking by anonymity set. When revoked, anonymises all visits using their current anonymity set. |
|
|
377
|
+
| cookie | boolean | Optional. Sets the user's preference for tracking by cookies. When revoked, deletes the `skadi_id` cookie. |
|
|
378
|
+
| user | boolean | Optional. Sets the user's preference for tracking by their user account. When revoked, de-links all visits from their user account. |
|
|
379
|
+
|
|
380
|
+
#### Consent schema
|
|
381
|
+
|
|
382
|
+
Consent is stored in the `skadi_visits` table as follows:
|
|
383
|
+
|
|
384
|
+
| Consent | SQL |
|
|
385
|
+
|---------------|------------------------------------------------------------------------------------|
|
|
386
|
+
| cookie | `skadi_visits.cookies_enabled = true` |
|
|
387
|
+
| anonymity_set | `skadi_visits.tracking_token IS NOT NULL AND skadi_visits.cookies_enabled = false` |
|
|
388
|
+
| user | `skadi_visits.user_id IS NOT NULL` |
|
|
389
|
+
|
|
390
|
+
|
|
391
|
+
## Dashboard
|
|
392
|
+
|
|
393
|
+
Skadi includes dashboards for exploring the data it collects. The root of the mounted engine lists every dashboard, so with the default setup the list can be found at `/skadi` and each dashboard at `/skadi/:id`.
|
|
394
|
+
|
|
395
|
+
|
|
396
|
+
### Permissions
|
|
397
|
+
|
|
398
|
+
The dashboard is disabled until you tell Skadi how to authorise users. Each option names a method on your `ApplicationController` that returns `true` or `false` for the current request. The dashboard controller inherits from your `ApplicationController`, so these methods can use anything available there.
|
|
399
|
+
|
|
400
|
+
```ruby
|
|
401
|
+
Skadi.configure do |config|
|
|
402
|
+
# Required: whether the current user can view the dashboard
|
|
403
|
+
config.dashboard_view_controller_method = :skadi_dashboard_can_view
|
|
404
|
+
|
|
405
|
+
# Whether the current user can create, edit and delete dashboards, tabs, charts and datasets
|
|
406
|
+
config.dashboard_edit_controller_method = :skadi_dashboard_can_edit
|
|
407
|
+
|
|
408
|
+
# Whether the current user can write raw SQL datasets. See "Restricting dashboard SQL" below
|
|
409
|
+
config.dashboard_dangerously_use_sql_controller_method = :skadi_dashboard_can_use_sql
|
|
410
|
+
|
|
411
|
+
# Called instead of responding with 403 Forbidden, e.g. to redirect to a login page
|
|
412
|
+
config.dashboard_forbidden_method = :redirect_to_login
|
|
413
|
+
end
|
|
414
|
+
```
|
|
415
|
+
|
|
416
|
+
|
|
417
|
+
### Building charts
|
|
418
|
+
|
|
419
|
+
A dashboard consists of multiple tabs. Each tab has a default date range and a list of charts, and each chart has one or more datasets. Users with edit permission can add, edit, duplicate, reorder and delete charts, and changes are saved automatically.
|
|
420
|
+
|
|
421
|
+
A chart is a line chart, a bar chart or a table. Line and bar charts plot a time series by day, week or month, or a single total. Tables list rows, ten per page.
|
|
422
|
+
|
|
423
|
+
A dataset is built from one of Skadi's tables (visits, views, events or demographics) or a [custom table](#custom-fields-and-tables):
|
|
424
|
+
|
|
425
|
+
| Option | Description |
|
|
426
|
+
|---------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
|
427
|
+
| Count by | What to count, e.g. visits or unique visitors. |
|
|
428
|
+
| Split by | Fields to break the count down by, giving one line or bar per value. |
|
|
429
|
+
| Filters | Conditions on the table's fields, such as `path = /pricing` or `utm_source not empty`. |
|
|
430
|
+
| Linked tables | Views can be split and filtered by their visit, and events by their view and visit. A linked table can be marked as required to exclude rows without one. |
|
|
431
|
+
| Fields | For tables, which fields to show. |
|
|
432
|
+
|
|
433
|
+
Two further dataset types build on the others:
|
|
434
|
+
|
|
435
|
+
* **Percentage** divides one dataset in the chart by another, e.g. checkouts as a percentage of visits.
|
|
436
|
+
* **SQL** runs a raw query, for users with SQL permission. For line and bar charts it must return `date`, `split` and `count` columns; for tables it can return anything.
|
|
437
|
+
|
|
438
|
+
Any chart can be switched to show its data as a table instead.
|
|
439
|
+
|
|
440
|
+
|
|
441
|
+
### Custom fields and tables
|
|
442
|
+
|
|
443
|
+
Event properties can be exposed as fields with `dashboard_custom_event_fields`, so they can be filtered and split like any other field:
|
|
444
|
+
|
|
445
|
+
```ruby
|
|
446
|
+
config.dashboard_custom_event_fields = {
|
|
447
|
+
plan: { type: :one_of, options: %w[free pro], filter: true, split: true, sql: "properties->>'plan'" },
|
|
448
|
+
}
|
|
449
|
+
```
|
|
450
|
+
|
|
451
|
+
Your own tables can be added as datasets with `dashboard_custom_schema`. See the generated initializer for the full format of both options.
|
|
452
|
+
|
|
453
|
+
|
|
454
|
+
### Restricting dashboard SQL
|
|
455
|
+
|
|
456
|
+
Users granted `dashboard_dangerously_use_sql_controller_method` can run arbitrary SQL from the dashboard, with some limited restrictions to prevent modifying data. By default this runs on your application's database connection. To restrict it, add a second entry to `config/database.yml` that connects to the same database as a read-only database user (see the Rails guide on [multiple databases](https://guides.rubyonrails.org/active_record_multiple_databases.html)), and tell Skadi to run dashboard queries on it:
|
|
457
|
+
|
|
458
|
+
```ruby
|
|
459
|
+
Skadi.configure do |config|
|
|
460
|
+
config.dashboard_database = :skadi_readonly
|
|
461
|
+
end
|
|
462
|
+
```
|
|
96
463
|
|
|
97
|
-
Many privacy laws also require that users be given the option to opt-out of anonymisation-set tracking. Calling the `window.skadi.optOut()` function in the front end will set a cookie that will prevent Skadi from generating anonymisation sets for that user. Their views and events will still be collected, but no personal data will be stored.
|
|
98
464
|
|
|
99
465
|
## Configuration
|
|
100
466
|
|
|
101
|
-
|
|
102
|
-
> add configuration details
|
|
467
|
+
See the [default initializer](lib/generators/skadi/install/templates/skadi_initializer.rb) or Skadi's [Configuration class](lib/skadi/configuration.rb) for all options and their defaults.
|
|
103
468
|
|
|
104
469
|
|
|
470
|
+
## Limitations
|
|
105
471
|
|
|
472
|
+
* Events marked sensitive are not linked to a view or visit, and their timestamp is set to the start of the day. However, they still use sequential ids, so their position relative to other events can reveal roughly when they were created, especially if a sensitive and non-sensitive event are created in the same request.
|
|
473
|
+
* The daily pepper used for anonymity sets is stored in `Rails.cache` and discarded when it expires. A shared store (SolidCache, Redis or Memcached) is required. NullStore disables anonymity sets, and MemoryStore breaks the grouping when Rails runs across multiple processes or servers. Skadi logs a warning at boot in both cases.
|
|
474
|
+
* The tracking endpoint is rate limited per IP address (200 requests per minute by default, see `tracking_rate_limit` in the [configuration](lib/skadi/configuration.rb)). The counter is also stored in `Rails.cache`, so NullStore disables the limit and MemoryStore counts each process separately. Each page view sends at least two requests, so sites with many users behind one IP address may need a higher limit.
|
|
106
475
|
|
|
107
|
-
## Todo
|
|
108
476
|
|
|
109
|
-
|
|
110
|
-
* Document sequential events can still be re-derived based on `id`
|
|
111
|
-
* Document cache storage/TTL requirements or supply a job to clear the cache
|
|
477
|
+
[the UK ICO's 'simple and free' means to object]: https://ico.org.uk/for-organisations/direct-marketing-and-privacy-and-electronic-communications/guidance-on-the-use-of-storage-and-access-technologies/what-are-the-exceptions/#statistical
|