umami-ruby 0.1.2 → 0.2.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.
data/lib/umami/client.rb CHANGED
@@ -47,10 +47,10 @@ module Umami
47
47
 
48
48
  # Verify the authentication token
49
49
  #
50
- # @return [Hash] Token verification result
50
+ # @return [Hash] Token verification result containing user information
51
51
  # @see https://umami.is/docs/api/authentication#post-/api/auth/verify
52
52
  def verify_token
53
- get("/api/auth/verify")
53
+ post("/api/auth/verify")
54
54
  end
55
55
 
56
56
  # Authentication endpoints
@@ -76,32 +76,109 @@ module Umami
76
76
  raise Umami::AuthenticationError, "Authentication failed: #{e.message}"
77
77
  end
78
78
 
79
+ # -------- Me endpoints --------
80
+
81
+ # Get information about the current authenticated user
82
+ #
83
+ # @return [Hash] Current user information including token, authKey, shareToken, and user details
84
+ # @see https://umami.is/docs/api/me#get-/api/me
85
+ def me
86
+ get("/api/me")
87
+ end
88
+
89
+ # Get all teams for the current authenticated user
90
+ #
91
+ # @param params [Hash] Query parameters
92
+ # @option params [Integer] :page Page number (default: 1)
93
+ # @option params [Integer] :pageSize Number of results per page
94
+ # @return [Hash] Paginated list of teams with members
95
+ # @see https://umami.is/docs/api/me#get-/api/me/teams
96
+ def my_teams(params = {})
97
+ get("/api/me/teams", params)
98
+ end
99
+
100
+ # Get all websites for the current authenticated user
101
+ #
102
+ # @param params [Hash] Query parameters
103
+ # @option params [Boolean] :includeTeams Include websites where user is team owner
104
+ # @return [Hash] Paginated list of websites
105
+ # @see https://umami.is/docs/api/me#get-/api/me/websites
106
+ def my_websites(params = {})
107
+ get("/api/me/websites", params)
108
+ end
109
+
110
+ # -------- Admin endpoints --------
111
+
112
+ # Get all users (admin access required, self-hosted only)
113
+ #
114
+ # @param params [Hash] Query parameters
115
+ # @option params [String] :search Search text
116
+ # @option params [Integer] :page Page number (default: 1)
117
+ # @option params [Integer] :pageSize Number of results per page (default: 20)
118
+ # @return [Hash] Paginated list of all users
119
+ # @see https://umami.is/docs/api/admin#get-/api/admin/users
120
+ def admin_users(params = {})
121
+ get("/api/admin/users", params)
122
+ end
123
+
124
+ # Get all websites (admin access required, self-hosted only)
125
+ #
126
+ # @param params [Hash] Query parameters
127
+ # @option params [String] :search Search text
128
+ # @option params [Integer] :page Page number (default: 1)
129
+ # @option params [Integer] :pageSize Number of results per page (default: 20)
130
+ # @return [Hash] Paginated list of all websites
131
+ # @see https://umami.is/docs/api/admin#get-/api/admin/websites
132
+ def admin_websites(params = {})
133
+ get("/api/admin/websites", params)
134
+ end
135
+
136
+ # Get all teams (admin access required, self-hosted only)
137
+ #
138
+ # @param params [Hash] Query parameters
139
+ # @option params [String] :search Search text
140
+ # @option params [Integer] :page Page number (default: 1)
141
+ # @option params [Integer] :pageSize Number of results per page (default: 20)
142
+ # @return [Hash] Paginated list of all teams
143
+ # @see https://umami.is/docs/api/admin#get-/api/admin/teams
144
+ def admin_teams(params = {})
145
+ get("/api/admin/teams", params)
146
+ end
147
+
79
148
  # -------- Users endpoints --------
80
149
 
81
150
  # Create a new user
82
151
  #
83
152
  # @param username [String] The user's username
84
153
  # @param password [String] The user's password
85
- # @param role [String] The user's role ('admin' or 'user')
154
+ # @param role [String] The user's role ('admin', 'user', or 'view-only')
155
+ # @param id [String, nil] Optional UUID to assign to the user
86
156
  # @return [Hash] Created user details
87
- # @see https://umami.is/docs/api/users-api#post-/api/users
88
- def create_user(username, password, role)
89
- post("/api/users", { username: username, password: password, role: role })
157
+ # @see https://umami.is/docs/api/users#post-/api/users
158
+ def create_user(username, password, role, id: nil)
159
+ params = { username: username, password: password, role: role }
160
+ params[:id] = id if id
161
+ post("/api/users", params)
90
162
  end
91
163
 
92
164
  # Get all users (admin access required)
93
165
  #
94
- # @return [Array<Hash>] List of all users
95
- # @see https://umami.is/docs/api/users-api#get-/api/admin/users
96
- def users
97
- get("/api/admin/users")
166
+ # @param params [Hash] Query parameters
167
+ # @option params [String] :search Search text
168
+ # @option params [Integer] :page Page number (default: 1)
169
+ # @option params [Integer] :pageSize Number of results per page (default: 20)
170
+ # @return [Hash] Paginated list of all users
171
+ # @see https://umami.is/docs/api/admin#get-/api/admin/users
172
+ # @deprecated Use {#admin_users} instead
173
+ def users(params = {})
174
+ admin_users(params)
98
175
  end
99
176
 
100
177
  # Get a user by ID
101
178
  #
102
179
  # @param user_id [String] The user's ID
103
180
  # @return [Hash] User details
104
- # @see https://umami.is/docs/api/users-api#get-/api/users/:userid
181
+ # @see https://umami.is/docs/api/users#get-/api/users/:userid
105
182
  def user(user_id)
106
183
  get("/api/users/#{user_id}")
107
184
  end
@@ -112,9 +189,9 @@ module Umami
112
189
  # @param params [Hash] User parameters to update
113
190
  # @option params [String] :username The user's new username
114
191
  # @option params [String] :password The user's new password
115
- # @option params [String] :role The user's new role
192
+ # @option params [String] :role The user's new role ('admin', 'user', or 'view-only')
116
193
  # @return [Hash] Updated user details
117
- # @see https://umami.is/docs/api/users-api#post-/api/users/:userid
194
+ # @see https://umami.is/docs/api/users#post-/api/users/:userid
118
195
  def update_user(user_id, params = {})
119
196
  post("/api/users/#{user_id}", params)
120
197
  end
@@ -122,8 +199,8 @@ module Umami
122
199
  # Delete a user
123
200
  #
124
201
  # @param user_id [String] The user's ID
125
- # @return [String] Confirmation message
126
- # @see https://umami.is/docs/api/users-api#delete-/api/users/:userid
202
+ # @return [Hash] Confirmation message
203
+ # @see https://umami.is/docs/api/users#delete-/api/users/:userid
127
204
  def delete_user(user_id)
128
205
  delete("/api/users/#{user_id}")
129
206
  end
@@ -132,12 +209,12 @@ module Umami
132
209
  #
133
210
  # @param user_id [String] The user's ID
134
211
  # @param params [Hash] Query parameters
135
- # @option params [String] :query Search text
136
- # @option params [Integer] :page Page number
212
+ # @option params [Boolean] :includeTeams Include team websites
213
+ # @option params [String] :search Search text
214
+ # @option params [Integer] :page Page number (default: 1)
137
215
  # @option params [Integer] :pageSize Number of results per page
138
- # @option params [String] :orderBy Column to order by
139
- # @return [Array<Hash>] List of user's websites
140
- # @see https://umami.is/docs/api/users-api#get-/api/users/:userid/websites
216
+ # @return [Hash] Paginated list of user's websites
217
+ # @see https://umami.is/docs/api/users#get-/api/users/:userid/websites
141
218
  def user_websites(user_id, params = {})
142
219
  get("/api/users/#{user_id}/websites", params)
143
220
  end
@@ -146,12 +223,10 @@ module Umami
146
223
  #
147
224
  # @param user_id [String] The user's ID
148
225
  # @param params [Hash] Query parameters
149
- # @option params [String] :query Search text
150
- # @option params [Integer] :page Page number
226
+ # @option params [Integer] :page Page number (default: 1)
151
227
  # @option params [Integer] :pageSize Number of results per page
152
- # @option params [String] :orderBy Column to order by
153
- # @return [Array<Hash>] List of user's teams
154
- # @see https://umami.is/docs/api/users-api#get-/api/users/:userid/teams
228
+ # @return [Hash] Paginated list of user's teams
229
+ # @see https://umami.is/docs/api/users#get-/api/users/:userid/teams
155
230
  def user_teams(user_id, params = {})
156
231
  get("/api/users/#{user_id}/teams", params)
157
232
  end
@@ -162,7 +237,7 @@ module Umami
162
237
  #
163
238
  # @param name [String] The team's name
164
239
  # @return [Hash] Created team details
165
- # @see https://umami.is/docs/api/teams-api#post-/api/teams
240
+ # @see https://umami.is/docs/api/teams#post-/api/teams
166
241
  def create_team(name)
167
242
  post("/api/teams", { name: name })
168
243
  end
@@ -170,12 +245,10 @@ module Umami
170
245
  # Get all teams
171
246
  #
172
247
  # @param params [Hash] Query parameters
173
- # @option params [String] :query Search text
174
- # @option params [Integer] :page Page number
248
+ # @option params [Integer] :page Page number (default: 1)
175
249
  # @option params [Integer] :pageSize Number of results per page
176
- # @option params [String] :orderBy Column to order by
177
- # @return [Array<Hash>] List of teams
178
- # @see https://umami.is/docs/api/teams-api#get-/api/teams
250
+ # @return [Hash] Paginated list of teams
251
+ # @see https://umami.is/docs/api/teams#get-/api/teams
179
252
  def teams(params = {})
180
253
  get("/api/teams", params)
181
254
  end
@@ -184,7 +257,7 @@ module Umami
184
257
  #
185
258
  # @param access_code [String] The team's access code
186
259
  # @return [Hash] Joined team details
187
- # @see https://umami.is/docs/api/teams-api#post-/api/teams/join
260
+ # @see https://umami.is/docs/api/teams#post-/api/teams/join
188
261
  def join_team(access_code)
189
262
  post("/api/teams/join", { accessCode: access_code })
190
263
  end
@@ -193,7 +266,7 @@ module Umami
193
266
  #
194
267
  # @param team_id [String] The team's ID
195
268
  # @return [Hash] Team details
196
- # @see https://umami.is/docs/api/teams-api#get-/api/teams/:teamid
269
+ # @see https://umami.is/docs/api/teams#get-/api/teams/:teamid
197
270
  def team(team_id)
198
271
  get("/api/teams/#{team_id}")
199
272
  end
@@ -205,7 +278,7 @@ module Umami
205
278
  # @option params [String] :name The team's new name
206
279
  # @option params [String] :accessCode The team's new access code
207
280
  # @return [Hash] Updated team details
208
- # @see https://umami.is/docs/api/teams-api#post-/api/teams/:teamid
281
+ # @see https://umami.is/docs/api/teams#post-/api/teams/:teamid
209
282
  def update_team(team_id, params = {})
210
283
  post("/api/teams/#{team_id}", params)
211
284
  end
@@ -213,8 +286,8 @@ module Umami
213
286
  # Delete a team
214
287
  #
215
288
  # @param team_id [String] The team's ID
216
- # @return [String] Confirmation message
217
- # @see https://umami.is/docs/api/teams-api#delete-/api/teams/:teamid
289
+ # @return [Hash] Confirmation message
290
+ # @see https://umami.is/docs/api/teams#delete-/api/teams/:teamid
218
291
  def delete_team(team_id)
219
292
  delete("/api/teams/#{team_id}")
220
293
  end
@@ -223,12 +296,11 @@ module Umami
223
296
  #
224
297
  # @param team_id [String] The team's ID
225
298
  # @param params [Hash] Query parameters
226
- # @option params [String] :query Search text
227
- # @option params [Integer] :page Page number
299
+ # @option params [String] :search Search text
300
+ # @option params [Integer] :page Page number (default: 1)
228
301
  # @option params [Integer] :pageSize Number of results per page
229
- # @option params [String] :orderBy Column to order by
230
- # @return [Array<Hash>] List of team users
231
- # @see https://umami.is/docs/api/teams-api#get-/api/teams/:teamid/users
302
+ # @return [Hash] Paginated list of team users
303
+ # @see https://umami.is/docs/api/teams#get-/api/teams/:teamid/users
232
304
  def team_users(team_id, params = {})
233
305
  get("/api/teams/#{team_id}/users", params)
234
306
  end
@@ -237,9 +309,9 @@ module Umami
237
309
  #
238
310
  # @param team_id [String] The team's ID
239
311
  # @param user_id [String] The user's ID
240
- # @param role [String] The user's role in the team
312
+ # @param role [String] The user's role in the team ('team-manager', 'team-member', or 'team-view-only')
241
313
  # @return [Hash] Added team user details
242
- # @see https://umami.is/docs/api/teams-api#post-/api/teams/:teamid/users
314
+ # @see https://umami.is/docs/api/teams#post-/api/teams/:teamid/users
243
315
  def add_team_user(team_id, user_id, role)
244
316
  post("/api/teams/#{team_id}/users", { userId: user_id, role: role })
245
317
  end
@@ -249,7 +321,7 @@ module Umami
249
321
  # @param team_id [String] The team's ID
250
322
  # @param user_id [String] The user's ID
251
323
  # @return [Hash] Team user details
252
- # @see https://umami.is/docs/api/teams-api#get-/api/teams/:teamid/users/:userid
324
+ # @see https://umami.is/docs/api/teams#get-/api/teams/:teamid/users/:userid
253
325
  def team_user(team_id, user_id)
254
326
  get("/api/teams/#{team_id}/users/#{user_id}")
255
327
  end
@@ -258,9 +330,9 @@ module Umami
258
330
  #
259
331
  # @param team_id [String] The team's ID
260
332
  # @param user_id [String] The user's ID
261
- # @param role [String] The user's new role
262
- # @return [String] Confirmation message
263
- # @see https://umami.is/docs/api/teams-api#post-/api/teams/:teamid/users/:userid
333
+ # @param role [String] The user's new role ('team-manager', 'team-member', or 'team-view-only')
334
+ # @return [Hash] Confirmation message
335
+ # @see https://umami.is/docs/api/teams#post-/api/teams/:teamid/users/:userid
264
336
  def update_team_user(team_id, user_id, role)
265
337
  post("/api/teams/#{team_id}/users/#{user_id}", { role: role })
266
338
  end
@@ -269,8 +341,8 @@ module Umami
269
341
  #
270
342
  # @param team_id [String] The team's ID
271
343
  # @param user_id [String] The user's ID
272
- # @return [String] Confirmation message
273
- # @see https://umami.is/docs/api/teams-api#delete-/api/teams/:teamid/users/:userid
344
+ # @return [Hash] Confirmation message
345
+ # @see https://umami.is/docs/api/teams#delete-/api/teams/:teamid/users/:userid
274
346
  def delete_team_user(team_id, user_id)
275
347
  delete("/api/teams/#{team_id}/users/#{user_id}")
276
348
  end
@@ -279,12 +351,11 @@ module Umami
279
351
  #
280
352
  # @param team_id [String] The team's ID
281
353
  # @param params [Hash] Query parameters
282
- # @option params [String] :query Search text
283
- # @option params [Integer] :page Page number
354
+ # @option params [String] :search Search text
355
+ # @option params [Integer] :page Page number (default: 1)
284
356
  # @option params [Integer] :pageSize Number of results per page
285
- # @option params [String] :orderBy Column to order by
286
- # @return [Array<Hash>] List of team websites
287
- # @see https://umami.is/docs/api/teams-api#get-/api/teams/:teamid/websites
357
+ # @return [Hash] Paginated list of team websites
358
+ # @see https://umami.is/docs/api/teams#get-/api/teams/:teamid/websites
288
359
  def team_websites(team_id, params = {})
289
360
  get("/api/teams/#{team_id}/websites", params)
290
361
  end
@@ -294,12 +365,12 @@ module Umami
294
365
  # Get all websites
295
366
  #
296
367
  # @param params [Hash] Query parameters
297
- # @option params [String] :query Search text
298
- # @option params [Integer] :page Page number
368
+ # @option params [Boolean] :includeTeams Include websites where user is team owner
369
+ # @option params [String] :search Search text
370
+ # @option params [Integer] :page Page number (default: 1)
299
371
  # @option params [Integer] :pageSize Number of results per page
300
- # @option params [String] :orderBy Column to order by
301
- # @return [Array<Hash>] List of websites
302
- # @see https://umami.is/docs/api/websites-api#get-/api/websites
372
+ # @return [Hash] Paginated list of websites
373
+ # @see https://umami.is/docs/api/websites#get-/api/websites
303
374
  def websites(params = {})
304
375
  get("/api/websites", params)
305
376
  end
@@ -307,34 +378,35 @@ module Umami
307
378
  # Create a new website
308
379
  #
309
380
  # @param params [Hash] Website parameters
310
- # @option params [String] :domain The full domain of the tracked website
311
- # @option params [String] :name The name of the website in Umami
381
+ # @option params [String] :name The name of the website in Umami (required)
382
+ # @option params [String] :domain The full domain of the tracked website (required)
312
383
  # @option params [String] :shareId A unique string to enable a share url (optional)
313
384
  # @option params [String] :teamId The ID of the team the website will be created under (optional)
385
+ # @option params [String] :id Force a specific UUID for the website (optional)
314
386
  # @return [Hash] Created website details
315
- # @see https://umami.is/docs/api/websites-api#post-/api/websites
387
+ # @see https://umami.is/docs/api/websites#post-/api/websites
316
388
  def create_website(params = {})
317
389
  post("/api/websites", params)
318
390
  end
319
391
 
320
392
  # Get a website by ID
321
393
  #
322
- # @param id [String] The website's ID
394
+ # @param website_id [String] The website's ID
323
395
  # @return [Hash] Website details
324
- # @see https://umami.is/docs/api/websites-api#get-/api/websites/:websiteid
325
- def website(id)
326
- get("/api/websites/#{id}")
396
+ # @see https://umami.is/docs/api/websites#get-/api/websites/:websiteid
397
+ def website(website_id)
398
+ get("/api/websites/#{website_id}")
327
399
  end
328
400
 
329
401
  # Update a website
330
402
  #
331
403
  # @param website_id [String] The website's ID
332
404
  # @param params [Hash] Website parameters to update
333
- # @option params [String] :name The name of the website in Umami
334
- # @option params [String] :domain The full domain of the tracked website
405
+ # @option params [String] :name The name of the website in Umami (required)
406
+ # @option params [String] :domain The full domain of the tracked website (required)
335
407
  # @option params [String] :shareId A unique string to enable a share url
336
408
  # @return [Hash] Updated website details
337
- # @see https://umami.is/docs/api/websites-api#post-/api/websites/:websiteid
409
+ # @see https://umami.is/docs/api/websites#post-/api/websites/:websiteid
338
410
  def update_website(website_id, params = {})
339
411
  post("/api/websites/#{website_id}", params)
340
412
  end
@@ -342,8 +414,8 @@ module Umami
342
414
  # Delete a website
343
415
  #
344
416
  # @param website_id [String] The website's ID
345
- # @return [String] Confirmation message
346
- # @see https://umami.is/docs/api/websites-api#delete-/api/websites/:websiteid
417
+ # @return [Hash] Confirmation message
418
+ # @see https://umami.is/docs/api/websites#delete-/api/websites/:websiteid
347
419
  def delete_website(website_id)
348
420
  delete("/api/websites/#{website_id}")
349
421
  end
@@ -351,8 +423,8 @@ module Umami
351
423
  # Reset a website's data
352
424
  #
353
425
  # @param website_id [String] The website's ID
354
- # @return [String] Confirmation message
355
- # @see https://umami.is/docs/api/websites-api#post-/api/websites/:websiteid/reset
426
+ # @return [Hash] Confirmation message
427
+ # @see https://umami.is/docs/api/websites#post-/api/websites/:websiteid/reset
356
428
  def reset_website(website_id)
357
429
  post("/api/websites/#{website_id}/reset")
358
430
  end
@@ -361,176 +433,850 @@ module Umami
361
433
 
362
434
  # Get website statistics
363
435
  #
364
- # @param id [String] The website's ID
365
- # @param params [Hash] Query parameters
366
- # @option params [Integer] :startAt Timestamp (in ms) of starting date
367
- # @option params [Integer] :endAt Timestamp (in ms) of end date
368
- # @option params [String] :url Name of URL
369
- # @option params [String] :referrer Name of referrer
370
- # @option params [String] :title Name of page title
371
- # @option params [String] :query Name of query
372
- # @option params [String] :event Name of event
373
- # @option params [String] :os Name of operating system
374
- # @option params [String] :browser Name of browser
375
- # @option params [String] :device Name of device
376
- # @option params [String] :country Name of country
377
- # @option params [String] :region Name of region/state/province
378
- # @option params [String] :city Name of city
379
- # @return [Hash] Website statistics
436
+ # @param website_id [String] The website's ID
437
+ # @param params [Hash] Query parameters
438
+ # @option params [Integer] :startAt Timestamp (in ms) of starting date (required)
439
+ # @option params [Integer] :endAt Timestamp (in ms) of end date (required)
440
+ # @option params [String] :path Filter by URL path
441
+ # @option params [String] :referrer Filter by referrer
442
+ # @option params [String] :title Filter by page title
443
+ # @option params [String] :query Filter by query string
444
+ # @option params [String] :os Filter by operating system
445
+ # @option params [String] :browser Filter by browser
446
+ # @option params [String] :device Filter by device type
447
+ # @option params [String] :country Filter by country
448
+ # @option params [String] :region Filter by region/state/province
449
+ # @option params [String] :city Filter by city
450
+ # @option params [String] :hostname Filter by hostname
451
+ # @option params [String] :tag Filter by tag
452
+ # @option params [String] :segment Filter by segment UUID
453
+ # @option params [String] :cohort Filter by cohort UUID
454
+ # @return [Hash] Website statistics including pageviews, visitors, visits, bounces, totaltime
380
455
  # @see https://umami.is/docs/api/website-stats#get-/api/websites/:websiteid/stats
381
- def website_stats(id, params = {})
382
- get("/api/websites/#{id}/stats", params)
456
+ def website_stats(website_id, params = {})
457
+ get("/api/websites/#{website_id}/stats", params)
383
458
  end
384
459
 
385
- # Get active visitors for a website
460
+ # Get active visitors for a website (last 5 minutes)
386
461
  #
387
- # @param id [String] The website's ID
462
+ # @param website_id [String] The website's ID
388
463
  # @return [Hash] Number of active visitors
389
464
  # @see https://umami.is/docs/api/website-stats#get-/api/websites/:websiteid/active
390
- def website_active_visitors(id)
391
- get("/api/websites/#{id}/active")
465
+ def website_active_visitors(website_id)
466
+ get("/api/websites/#{website_id}/active")
392
467
  end
393
468
 
394
- # Get website events
469
+ # Get website pageviews within a time range
395
470
  #
396
- # @param id [String] The website's ID
471
+ # @param website_id [String] The website's ID
397
472
  # @param params [Hash] Query parameters
398
- # @option params [Integer] :startAt Timestamp (in ms) of starting date
399
- # @option params [Integer] :endAt Timestamp (in ms) of end date
400
- # @option params [String] :unit Time unit (year | month | hour | day)
401
- # @option params [String] :timezone Timezone (ex. America/Los_Angeles)
402
- # @option params [String] :url Name of URL
473
+ # @option params [Integer] :startAt Timestamp (in ms) of starting date (required)
474
+ # @option params [Integer] :endAt Timestamp (in ms) of end date (required)
475
+ # @option params [String] :unit Time unit for grouping ('minute', 'hour', 'day', 'month', 'year') (required)
476
+ # @option params [String] :timezone Timezone (e.g., 'America/Los_Angeles')
477
+ # @option params [String] :compare Comparison mode ('prev' or 'yoy')
478
+ # @option params [String] :path Filter by URL path
479
+ # @option params [String] :referrer Filter by referrer
480
+ # @option params [String] :title Filter by page title
481
+ # @option params [String] :os Filter by operating system
482
+ # @option params [String] :browser Filter by browser
483
+ # @option params [String] :device Filter by device type
484
+ # @option params [String] :country Filter by country
485
+ # @option params [String] :region Filter by region/state/province
486
+ # @option params [String] :city Filter by city
487
+ # @option params [String] :hostname Filter by hostname
488
+ # @option params [String] :tag Filter by tag
489
+ # @option params [String] :segment Filter by segment UUID
490
+ # @option params [String] :cohort Filter by cohort UUID
491
+ # @return [Hash] Pageviews and sessions arrays with timestamp and count
492
+ # @see https://umami.is/docs/api/website-stats#get-/api/websites/:websiteid/pageviews
493
+ def website_pageviews(website_id, params = {})
494
+ get("/api/websites/#{website_id}/pageviews", params)
495
+ end
496
+
497
+ # Get website events within a time range
498
+ #
499
+ # This method returns event data with optional time-series grouping.
500
+ # For paginated event lists with search, use {#website_events_list} instead.
501
+ #
502
+ # @param website_id [String] The website's ID
503
+ # @param params [Hash] Query parameters
504
+ # @option params [Integer] :startAt Timestamp (in ms) of starting date (required)
505
+ # @option params [Integer] :endAt Timestamp (in ms) of end date (required)
506
+ # @option params [String] :unit Time unit for grouping ('minute', 'hour', 'day', 'month', 'year')
507
+ # @option params [String] :timezone Timezone (e.g., 'America/Los_Angeles')
403
508
  # @return [Array<Hash>] Website events
509
+ # @see #website_events_list For paginated event list with search
404
510
  # @see https://umami.is/docs/api/website-stats#get-/api/websites/:websiteid/events
405
- def website_events(id, params = {})
406
- get("/api/websites/#{id}/events", params)
407
- end
408
-
409
- # Get website pageviews
410
- #
411
- # @param id [String] The website's ID
412
- # @param params [Hash] Query parameters
413
- # @option params [Integer] :startAt Timestamp (in ms) of starting date
414
- # @option params [Integer] :endAt Timestamp (in ms) of end date
415
- # @option params [String] :unit Time unit (year | month | hour | day)
416
- # @option params [String] :timezone Timezone (ex. America/Los_Angeles)
417
- # @option params [String] :url Name of URL
418
- # @option params [String] :referrer Name of referrer
419
- # @option params [String] :title Name of page title
420
- # @option params [String] :os Name of operating system
421
- # @option params [String] :browser Name of browser
422
- # @option params [String] :device Name of device
423
- # @option params [String] :country Name of country
424
- # @option params [String] :region Name of region/state/province
425
- # @option params [String] :city Name of city
426
- # @return [Hash] Website pageviews and sessions
427
- # @see https://umami.is/docs/api/website-stats#get-/api/websites/:websiteid/pageviews
428
- def website_pageviews(id, params = {})
429
- get("/api/websites/#{id}/pageviews", params)
511
+ def website_events(website_id, params = {})
512
+ get("/api/websites/#{website_id}/events", params)
513
+ end
514
+
515
+ # Get website events series within a time range
516
+ #
517
+ # @param website_id [String] The website's ID
518
+ # @param params [Hash] Query parameters
519
+ # @option params [Integer] :startAt Timestamp (in ms) of starting date (required)
520
+ # @option params [Integer] :endAt Timestamp (in ms) of end date (required)
521
+ # @option params [String] :unit Time unit for grouping ('minute', 'hour', 'day', 'month', 'year') (required)
522
+ # @option params [String] :timezone Timezone (e.g., 'America/Los_Angeles')
523
+ # @option params [String] :path Filter by URL path
524
+ # @option params [String] :referrer Filter by referrer
525
+ # @option params [String] :title Filter by page title
526
+ # @option params [String] :os Filter by operating system
527
+ # @option params [String] :browser Filter by browser
528
+ # @option params [String] :device Filter by device type
529
+ # @option params [String] :country Filter by country
530
+ # @option params [String] :region Filter by region/state/province
531
+ # @option params [String] :city Filter by city
532
+ # @option params [String] :hostname Filter by hostname
533
+ # @option params [String] :tag Filter by tag
534
+ # @option params [String] :segment Filter by segment UUID
535
+ # @option params [String] :cohort Filter by cohort UUID
536
+ # @return [Array<Hash>] Event series with x (event name), t (timestamp), y (count)
537
+ # @see https://umami.is/docs/api/website-stats#get-/api/websites/:websiteid/events/series
538
+ def website_events_series(website_id, params = {})
539
+ get("/api/websites/#{website_id}/events/series", params)
430
540
  end
431
541
 
432
542
  # Get website metrics
433
543
  #
434
- # @param id [String] The website's ID
435
- # @param params [Hash] Query parameters
436
- # @option params [Integer] :startAt Timestamp (in ms) of starting date
437
- # @option params [Integer] :endAt Timestamp (in ms) of end date
438
- # @option params [String] :type Metrics type (url | referrer | browser | os | device | country | event)
439
- # @option params [String] :url Name of URL
440
- # @option params [String] :referrer Name of referrer
441
- # @option params [String] :title Name of page title
442
- # @option params [String] :query Name of query
443
- # @option params [String] :event Name of event
444
- # @option params [String] :os Name of operating system
445
- # @option params [String] :browser Name of browser
446
- # @option params [String] :device Name of device
447
- # @option params [String] :country Name of country
448
- # @option params [String] :region Name of region/state/province
449
- # @option params [String] :city Name of city
450
- # @option params [String] :language Name of language
544
+ # @param website_id [String] The website's ID
545
+ # @param params [Hash] Query parameters
546
+ # @option params [Integer] :startAt Timestamp (in ms) of starting date (required)
547
+ # @option params [Integer] :endAt Timestamp (in ms) of end date (required)
548
+ # @option params [String] :type Metrics type (required): 'path', 'entry', 'exit', 'title', 'query', 'referrer', 'channel', 'domain', 'country', 'region', 'city', 'browser', 'os', 'device', 'language', 'screen', 'event', 'hostname', 'tag'
451
549
  # @option params [Integer] :limit Number of results to return (default: 500)
452
- # @return [Array<Hash>] Website metrics
550
+ # @option params [Integer] :offset Number of results to skip (default: 0)
551
+ # @option params [String] :path Filter by URL path
552
+ # @option params [String] :referrer Filter by referrer
553
+ # @option params [String] :title Filter by page title
554
+ # @option params [String] :query Filter by query string
555
+ # @option params [String] :os Filter by operating system
556
+ # @option params [String] :browser Filter by browser
557
+ # @option params [String] :device Filter by device type
558
+ # @option params [String] :country Filter by country
559
+ # @option params [String] :region Filter by region/state/province
560
+ # @option params [String] :city Filter by city
561
+ # @option params [String] :language Filter by language
562
+ # @option params [String] :tag Filter by tag
563
+ # @option params [String] :segment Filter by segment UUID
564
+ # @option params [String] :cohort Filter by cohort UUID
565
+ # @return [Array<Hash>] Website metrics with x (value) and y (visitor count)
453
566
  # @see https://umami.is/docs/api/website-stats#get-/api/websites/:websiteid/metrics
454
- def website_metrics(id, params = {})
455
- get("/api/websites/#{id}/metrics", params)
567
+ def website_metrics(website_id, params = {})
568
+ get("/api/websites/#{website_id}/metrics", params)
456
569
  end
457
570
 
458
- # Get event data events
571
+ # Get expanded website metrics with detailed engagement data
459
572
  #
460
573
  # @param website_id [String] The website's ID
461
574
  # @param params [Hash] Query parameters
462
- # @option params [Integer] :startAt Timestamp (in ms) of starting date
463
- # @option params [Integer] :endAt Timestamp (in ms) of end date
464
- # @option params [String] :event Event Name filter
465
- # @return [Array<Hash>] Event data events
466
- # @see https://umami.is/docs/api/event-data#get-/api/event-data/events
467
- def event_data_events(website_id, params = {})
468
- get("/api/event-data/events", params.merge(websiteId: website_id))
575
+ # @option params [Integer] :startAt Timestamp (in ms) of starting date (required)
576
+ # @option params [Integer] :endAt Timestamp (in ms) of end date (required)
577
+ # @option params [String] :type Metrics type (required): 'path', 'entry', 'exit', 'title', 'query', 'referrer', 'channel', 'domain', 'country', 'region', 'city', 'browser', 'os', 'device', 'language', 'screen', 'event', 'hostname', 'tag'
578
+ # @option params [Integer] :limit Number of results to return (default: 500)
579
+ # @option params [Integer] :offset Number of results to skip (default: 0)
580
+ # @option params [String] :path Filter by URL path
581
+ # @option params [String] :referrer Filter by referrer
582
+ # @option params [String] :title Filter by page title
583
+ # @option params [String] :query Filter by query string
584
+ # @option params [String] :os Filter by operating system
585
+ # @option params [String] :browser Filter by browser
586
+ # @option params [String] :device Filter by device type
587
+ # @option params [String] :country Filter by country
588
+ # @option params [String] :region Filter by region/state/province
589
+ # @option params [String] :city Filter by city
590
+ # @option params [String] :language Filter by language
591
+ # @option params [String] :tag Filter by tag
592
+ # @option params [String] :segment Filter by segment UUID
593
+ # @option params [String] :cohort Filter by cohort UUID
594
+ # @return [Array<Hash>] Expanded metrics with name, pageviews, visitors, visits, bounces, totaltime
595
+ # @see https://umami.is/docs/api/website-stats#get-/api/websites/:websiteid/metrics/expanded
596
+ def website_metrics_expanded(website_id, params = {})
597
+ get("/api/websites/#{website_id}/metrics/expanded", params)
469
598
  end
470
599
 
600
+ # -------- Sessions endpoints --------
601
+
602
+ # Get website sessions within a time range
603
+ #
604
+ # @param website_id [String] The website's ID
605
+ # @param params [Hash] Query parameters
606
+ # @option params [Integer] :startAt Timestamp (in ms) of starting date (required)
607
+ # @option params [Integer] :endAt Timestamp (in ms) of end date (required)
608
+ # @option params [String] :search Search text
609
+ # @option params [Integer] :page Page number (default: 1)
610
+ # @option params [Integer] :pageSize Number of results per page (default: 20)
611
+ # @option params [String] :path Filter by URL path
612
+ # @option params [String] :referrer Filter by referrer
613
+ # @option params [String] :title Filter by page title
614
+ # @option params [String] :query Filter by query string
615
+ # @option params [String] :os Filter by operating system
616
+ # @option params [String] :browser Filter by browser
617
+ # @option params [String] :device Filter by device type
618
+ # @option params [String] :country Filter by country
619
+ # @option params [String] :region Filter by region/state/province
620
+ # @option params [String] :city Filter by city
621
+ # @option params [String] :hostname Filter by hostname
622
+ # @option params [String] :tag Filter by tag
623
+ # @option params [String] :segment Filter by segment UUID
624
+ # @option params [String] :cohort Filter by cohort UUID
625
+ # @return [Hash] Paginated list of sessions
626
+ # @see https://umami.is/docs/api/sessions#get-/api/websites/:websiteid/sessions
627
+ def website_sessions(website_id, params = {})
628
+ get("/api/websites/#{website_id}/sessions", params)
629
+ end
471
630
 
472
- # -------- Event data endpoints --------
631
+ # Get summarized session statistics
632
+ #
633
+ # @param website_id [String] The website's ID
634
+ # @param params [Hash] Query parameters
635
+ # @option params [Integer] :startAt Timestamp (in ms) of starting date (required)
636
+ # @option params [Integer] :endAt Timestamp (in ms) of end date (required)
637
+ # @option params [String] :path Filter by URL path
638
+ # @option params [String] :referrer Filter by referrer
639
+ # @option params [String] :title Filter by page title
640
+ # @option params [String] :query Filter by query string
641
+ # @option params [String] :os Filter by operating system
642
+ # @option params [String] :browser Filter by browser
643
+ # @option params [String] :device Filter by device type
644
+ # @option params [String] :country Filter by country
645
+ # @option params [String] :region Filter by region/state/province
646
+ # @option params [String] :city Filter by city
647
+ # @option params [String] :hostname Filter by hostname
648
+ # @option params [String] :tag Filter by tag
649
+ # @option params [String] :segment Filter by segment UUID
650
+ # @option params [String] :cohort Filter by cohort UUID
651
+ # @return [Hash] Session statistics including pageviews, visitors, visits, countries, events
652
+ # @see https://umami.is/docs/api/sessions#get-/api/websites/:websiteid/sessions/stats
653
+ def website_sessions_stats(website_id, params = {})
654
+ get("/api/websites/#{website_id}/sessions/stats", params)
655
+ end
473
656
 
474
- # Get event data fields
657
+ # Get session counts by hour of weekday
475
658
  #
476
659
  # @param website_id [String] The website's ID
477
660
  # @param params [Hash] Query parameters
478
- # @option params [Integer] :startAt Timestamp (in ms) of starting date
479
- # @option params [Integer] :endAt Timestamp (in ms) of end date
480
- # @return [Array<Hash>] Event data fields
481
- # @see https://umami.is/docs/api/event-data#get-/api/event-data/fields
482
- def event_data_fields(website_id, params = {})
483
- get("/api/event-data/fields", params.merge(websiteId: website_id))
661
+ # @option params [Integer] :startAt Timestamp (in ms) of starting date (required)
662
+ # @option params [Integer] :endAt Timestamp (in ms) of end date (required)
663
+ # @option params [String] :timezone Timezone (e.g., 'America/Los_Angeles') (required)
664
+ # @option params [String] :path Filter by URL path
665
+ # @option params [String] :referrer Filter by referrer
666
+ # @option params [String] :title Filter by page title
667
+ # @option params [String] :query Filter by query string
668
+ # @option params [String] :os Filter by operating system
669
+ # @option params [String] :browser Filter by browser
670
+ # @option params [String] :device Filter by device type
671
+ # @option params [String] :country Filter by country
672
+ # @option params [String] :region Filter by region/state/province
673
+ # @option params [String] :city Filter by city
674
+ # @option params [String] :hostname Filter by hostname
675
+ # @option params [String] :tag Filter by tag
676
+ # @option params [String] :segment Filter by segment UUID
677
+ # @option params [String] :cohort Filter by cohort UUID
678
+ # @return [Array<Array>] 7x24 matrix of session counts by weekday and hour
679
+ # @see https://umami.is/docs/api/sessions#get-/api/websites/:websiteid/sessions/weekly
680
+ def website_sessions_weekly(website_id, params = {})
681
+ get("/api/websites/#{website_id}/sessions/weekly", params)
484
682
  end
485
683
 
486
- # Get event data stats
684
+ # Get details for an individual session
685
+ #
686
+ # @param website_id [String] The website's ID
687
+ # @param session_id [String] The session's ID
688
+ # @return [Hash] Session details including browser, os, device, visits, views, events, totaltime
689
+ # @see https://umami.is/docs/api/sessions#get-/api/websites/:websiteid/sessions/:sessionid
690
+ def website_session(website_id, session_id)
691
+ get("/api/websites/#{website_id}/sessions/#{session_id}")
692
+ end
693
+
694
+ # Get activity for an individual session
695
+ #
696
+ # @param website_id [String] The website's ID
697
+ # @param session_id [String] The session's ID
698
+ # @param params [Hash] Query parameters
699
+ # @option params [Integer] :startAt Timestamp (in ms) of starting date (required)
700
+ # @option params [Integer] :endAt Timestamp (in ms) of end date (required)
701
+ # @return [Array<Hash>] Session activity records
702
+ # @see https://umami.is/docs/api/sessions#get-/api/websites/:websiteid/sessions/:sessionid/activity
703
+ def website_session_activity(website_id, session_id, params = {})
704
+ get("/api/websites/#{website_id}/sessions/#{session_id}/activity", params)
705
+ end
706
+
707
+ # Get properties for an individual session
708
+ #
709
+ # @param website_id [String] The website's ID
710
+ # @param session_id [String] The session's ID
711
+ # @return [Array<Hash>] Session properties
712
+ # @see https://umami.is/docs/api/sessions#get-/api/websites/:websiteid/sessions/:sessionid/properties
713
+ def website_session_properties(website_id, session_id)
714
+ get("/api/websites/#{website_id}/sessions/#{session_id}/properties")
715
+ end
716
+
717
+ # Get session data property counts
718
+ #
719
+ # @param website_id [String] The website's ID
720
+ # @param params [Hash] Query parameters
721
+ # @option params [Integer] :startAt Timestamp (in ms) of starting date (required)
722
+ # @option params [Integer] :endAt Timestamp (in ms) of end date (required)
723
+ # @option params [String] :path Filter by URL path
724
+ # @option params [String] :referrer Filter by referrer
725
+ # @option params [String] :title Filter by page title
726
+ # @option params [String] :query Filter by query string
727
+ # @option params [String] :os Filter by operating system
728
+ # @option params [String] :browser Filter by browser
729
+ # @option params [String] :device Filter by device type
730
+ # @option params [String] :country Filter by country
731
+ # @option params [String] :region Filter by region/state/province
732
+ # @option params [String] :city Filter by city
733
+ # @option params [String] :hostname Filter by hostname
734
+ # @option params [String] :tag Filter by tag
735
+ # @option params [String] :segment Filter by segment UUID
736
+ # @option params [String] :cohort Filter by cohort UUID
737
+ # @return [Array<Hash>] Property aggregations with propertyName and total
738
+ # @see https://umami.is/docs/api/sessions#get-/api/websites/:websiteid/session-data/properties
739
+ def website_session_data_properties(website_id, params = {})
740
+ get("/api/websites/#{website_id}/session-data/properties", params)
741
+ end
742
+
743
+ # Get session data value counts for a property
487
744
  #
488
745
  # @param website_id [String] The website's ID
489
746
  # @param params [Hash] Query parameters
490
- # @option params [Integer] :startAt Timestamp (in ms) of starting date
491
- # @option params [Integer] :endAt Timestamp (in ms) of end date
492
- # @return [Array<Hash>] Event data stats
493
- # @see https://umami.is/docs/api/event-data#get-/api/event-data/stats
747
+ # @option params [Integer] :startAt Timestamp (in ms) of starting date (required)
748
+ # @option params [Integer] :endAt Timestamp (in ms) of end date (required)
749
+ # @option params [String] :propertyName Property name to query (required)
750
+ # @option params [String] :path Filter by URL path
751
+ # @option params [String] :referrer Filter by referrer
752
+ # @option params [String] :title Filter by page title
753
+ # @option params [String] :query Filter by query string
754
+ # @option params [String] :os Filter by operating system
755
+ # @option params [String] :browser Filter by browser
756
+ # @option params [String] :device Filter by device type
757
+ # @option params [String] :country Filter by country
758
+ # @option params [String] :region Filter by region/state/province
759
+ # @option params [String] :city Filter by city
760
+ # @option params [String] :hostname Filter by hostname
761
+ # @option params [String] :tag Filter by tag
762
+ # @option params [String] :segment Filter by segment UUID
763
+ # @option params [String] :cohort Filter by cohort UUID
764
+ # @return [Array<Hash>] Value aggregations with value and total
765
+ # @see https://umami.is/docs/api/sessions#get-/api/websites/:websiteid/session-data/values
766
+ def website_session_data_values(website_id, params = {})
767
+ get("/api/websites/#{website_id}/session-data/values", params)
768
+ end
769
+
770
+ # -------- Events endpoints --------
771
+
772
+ # Get website event details within a time range (paginated list)
773
+ #
774
+ # This method returns a paginated list of individual events with full details
775
+ # and supports search and filtering. For time-series grouped event data,
776
+ # use {#website_events} or {#website_events_series} instead.
777
+ #
778
+ # @param website_id [String] The website's ID
779
+ # @param params [Hash] Query parameters
780
+ # @option params [Integer] :startAt Timestamp (in ms) of starting date (required)
781
+ # @option params [Integer] :endAt Timestamp (in ms) of end date (required)
782
+ # @option params [String] :search Search text
783
+ # @option params [Integer] :page Page number (default: 1)
784
+ # @option params [Integer] :pageSize Number of results per page (default: 20)
785
+ # @option params [String] :path Filter by URL path
786
+ # @option params [String] :referrer Filter by referrer
787
+ # @option params [String] :title Filter by page title
788
+ # @option params [String] :query Filter by query string
789
+ # @option params [String] :os Filter by operating system
790
+ # @option params [String] :browser Filter by browser
791
+ # @option params [String] :device Filter by device type
792
+ # @option params [String] :country Filter by country
793
+ # @option params [String] :region Filter by region/state/province
794
+ # @option params [String] :city Filter by city
795
+ # @option params [String] :hostname Filter by hostname
796
+ # @option params [String] :tag Filter by tag
797
+ # @option params [String] :segment Filter by segment UUID
798
+ # @option params [String] :cohort Filter by cohort UUID
799
+ # @return [Hash] Paginated list of events with full event details
800
+ # @see #website_events For time-series grouped event data
801
+ # @see #website_events_series For event series with x/t/y format
802
+ # @see https://umami.is/docs/api/events#get-/api/websites/:websiteid/events
803
+ def website_events_list(website_id, params = {})
804
+ get("/api/websites/#{website_id}/events", params)
805
+ end
806
+
807
+ # Get event data for an individual event
808
+ #
809
+ # @param website_id [String] The website's ID
810
+ # @param event_id [String] The event's ID
811
+ # @return [Array<Hash>] Event data properties
812
+ # @see https://umami.is/docs/api/events#get-/api/websites/:websiteid/event-data/:eventid
813
+ def website_event_data(website_id, event_id)
814
+ get("/api/websites/#{website_id}/event-data/#{event_id}")
815
+ end
816
+
817
+ # Get event data names, properties, and counts
818
+ #
819
+ # @param website_id [String] The website's ID
820
+ # @param params [Hash] Query parameters
821
+ # @option params [Integer] :startAt Timestamp (in ms) of starting date (required)
822
+ # @option params [Integer] :endAt Timestamp (in ms) of end date (required)
823
+ # @option params [String] :event Event name filter
824
+ # @option params [String] :path Filter by URL path
825
+ # @option params [String] :referrer Filter by referrer
826
+ # @option params [String] :title Filter by page title
827
+ # @option params [String] :query Filter by query string
828
+ # @option params [String] :os Filter by operating system
829
+ # @option params [String] :browser Filter by browser
830
+ # @option params [String] :device Filter by device type
831
+ # @option params [String] :country Filter by country
832
+ # @option params [String] :region Filter by region/state/province
833
+ # @option params [String] :city Filter by city
834
+ # @option params [String] :hostname Filter by hostname
835
+ # @option params [String] :tag Filter by tag
836
+ # @option params [String] :segment Filter by segment UUID
837
+ # @option params [String] :cohort Filter by cohort UUID
838
+ # @return [Array<Hash>] Event data with eventName, propertyName, dataType, total
839
+ # @see https://umami.is/docs/api/events#get-/api/websites/:websiteid/event-data/events
840
+ def website_event_data_events(website_id, params = {})
841
+ get("/api/websites/#{website_id}/event-data/events", params)
842
+ end
843
+
844
+ # Get event data fields within a time range
845
+ #
846
+ # @param website_id [String] The website's ID
847
+ # @param params [Hash] Query parameters
848
+ # @option params [Integer] :startAt Timestamp (in ms) of starting date (required)
849
+ # @option params [Integer] :endAt Timestamp (in ms) of end date (required)
850
+ # @option params [String] :path Filter by URL path
851
+ # @option params [String] :referrer Filter by referrer
852
+ # @option params [String] :title Filter by page title
853
+ # @option params [String] :query Filter by query string
854
+ # @option params [String] :os Filter by operating system
855
+ # @option params [String] :browser Filter by browser
856
+ # @option params [String] :device Filter by device type
857
+ # @option params [String] :country Filter by country
858
+ # @option params [String] :region Filter by region/state/province
859
+ # @option params [String] :city Filter by city
860
+ # @option params [String] :hostname Filter by hostname
861
+ # @option params [String] :tag Filter by tag
862
+ # @option params [String] :segment Filter by segment UUID
863
+ # @option params [String] :cohort Filter by cohort UUID
864
+ # @return [Array<Hash>] Event data fields with propertyName, dataType, value, total
865
+ # @see https://umami.is/docs/api/events#get-/api/websites/:websiteid/event-data/fields
866
+ def website_event_data_fields(website_id, params = {})
867
+ get("/api/websites/#{website_id}/event-data/fields", params)
868
+ end
869
+
870
+ # Get event name and property counts
871
+ #
872
+ # @param website_id [String] The website's ID
873
+ # @param params [Hash] Query parameters
874
+ # @option params [Integer] :startAt Timestamp (in ms) of starting date (required)
875
+ # @option params [Integer] :endAt Timestamp (in ms) of end date (required)
876
+ # @option params [String] :path Filter by URL path
877
+ # @option params [String] :referrer Filter by referrer
878
+ # @option params [String] :title Filter by page title
879
+ # @option params [String] :query Filter by query string
880
+ # @option params [String] :os Filter by operating system
881
+ # @option params [String] :browser Filter by browser
882
+ # @option params [String] :device Filter by device type
883
+ # @option params [String] :country Filter by country
884
+ # @option params [String] :region Filter by region/state/province
885
+ # @option params [String] :city Filter by city
886
+ # @option params [String] :hostname Filter by hostname
887
+ # @option params [String] :tag Filter by tag
888
+ # @option params [String] :segment Filter by segment UUID
889
+ # @option params [String] :cohort Filter by cohort UUID
890
+ # @return [Array<Hash>] Event properties with eventName, propertyName, total
891
+ # @see https://umami.is/docs/api/events#get-/api/websites/:websiteid/event-data/properties
892
+ def website_event_data_properties(website_id, params = {})
893
+ get("/api/websites/#{website_id}/event-data/properties", params)
894
+ end
895
+
896
+ # Get event data value counts for a given event and property
897
+ #
898
+ # @param website_id [String] The website's ID
899
+ # @param params [Hash] Query parameters
900
+ # @option params [Integer] :startAt Timestamp (in ms) of starting date (required)
901
+ # @option params [Integer] :endAt Timestamp (in ms) of end date (required)
902
+ # @option params [String] :event Event name (required)
903
+ # @option params [String] :propertyName Property name (required)
904
+ # @option params [String] :path Filter by URL path
905
+ # @option params [String] :referrer Filter by referrer
906
+ # @option params [String] :title Filter by page title
907
+ # @option params [String] :query Filter by query string
908
+ # @option params [String] :os Filter by operating system
909
+ # @option params [String] :browser Filter by browser
910
+ # @option params [String] :device Filter by device type
911
+ # @option params [String] :country Filter by country
912
+ # @option params [String] :region Filter by region/state/province
913
+ # @option params [String] :city Filter by city
914
+ # @option params [String] :hostname Filter by hostname
915
+ # @option params [String] :tag Filter by tag
916
+ # @option params [String] :segment Filter by segment UUID
917
+ # @option params [String] :cohort Filter by cohort UUID
918
+ # @return [Array<Hash>] Value counts with value and total
919
+ # @see https://umami.is/docs/api/events#get-/api/websites/:websiteid/event-data/values
920
+ def website_event_data_values(website_id, params = {})
921
+ get("/api/websites/#{website_id}/event-data/values", params)
922
+ end
923
+
924
+ # Get aggregated event statistics
925
+ #
926
+ # @param website_id [String] The website's ID
927
+ # @param params [Hash] Query parameters
928
+ # @option params [Integer] :startAt Timestamp (in ms) of starting date (required)
929
+ # @option params [Integer] :endAt Timestamp (in ms) of end date (required)
930
+ # @option params [String] :path Filter by URL path
931
+ # @option params [String] :referrer Filter by referrer
932
+ # @option params [String] :title Filter by page title
933
+ # @option params [String] :query Filter by query string
934
+ # @option params [String] :os Filter by operating system
935
+ # @option params [String] :browser Filter by browser
936
+ # @option params [String] :device Filter by device type
937
+ # @option params [String] :country Filter by country
938
+ # @option params [String] :region Filter by region/state/province
939
+ # @option params [String] :city Filter by city
940
+ # @option params [String] :hostname Filter by hostname
941
+ # @option params [String] :tag Filter by tag
942
+ # @option params [String] :segment Filter by segment UUID
943
+ # @option params [String] :cohort Filter by cohort UUID
944
+ # @return [Array<Hash>] Event stats with events, properties, records counts
945
+ # @see https://umami.is/docs/api/events#get-/api/websites/:websiteid/event-data/stats
946
+ def website_event_data_stats(website_id, params = {})
947
+ get("/api/websites/#{website_id}/event-data/stats", params)
948
+ end
949
+
950
+ # -------- Deprecated event data methods --------
951
+
952
+ # @deprecated Use {#website_event_data_events} instead
953
+ def event_data_events(website_id, params = {})
954
+ warn "[DEPRECATION] `event_data_events` is deprecated. Use `website_event_data_events` instead."
955
+ website_event_data_events(website_id, params)
956
+ end
957
+
958
+ # @deprecated Use {#website_event_data_fields} instead
959
+ def event_data_fields(website_id, params = {})
960
+ warn "[DEPRECATION] `event_data_fields` is deprecated. Use `website_event_data_fields` instead."
961
+ website_event_data_fields(website_id, params)
962
+ end
963
+
964
+ # @deprecated Use {#website_event_data_stats} instead
494
965
  def event_data_stats(website_id, params = {})
495
- get("/api/event-data/stats", params.merge(websiteId: website_id))
966
+ warn "[DEPRECATION] `event_data_stats` is deprecated. Use `website_event_data_stats` instead."
967
+ website_event_data_stats(website_id, params)
968
+ end
969
+
970
+ # -------- Realtime endpoints --------
971
+
972
+ # Get realtime stats for a website (last 30 minutes)
973
+ #
974
+ # @param website_id [String] The website's ID
975
+ # @return [Hash] Realtime data including countries, urls, referrers, events, series, totals
976
+ # @see https://umami.is/docs/api/realtime#get-/api/realtime/:websiteid
977
+ def realtime(website_id)
978
+ get("/api/realtime/#{website_id}")
979
+ end
980
+
981
+ # -------- Links endpoints --------
982
+
983
+ # Get all links
984
+ #
985
+ # @param params [Hash] Query parameters
986
+ # @option params [String] :search Search text
987
+ # @option params [Integer] :page Page number (default: 1)
988
+ # @option params [Integer] :pageSize Number of results per page
989
+ # @return [Hash] Paginated list of links
990
+ # @see https://umami.is/docs/api/links#get-/api/links
991
+ def links(params = {})
992
+ get("/api/links", params)
993
+ end
994
+
995
+ # Get a link by ID
996
+ #
997
+ # @param link_id [String] The link's ID
998
+ # @return [Hash] Link details
999
+ # @see https://umami.is/docs/api/links#get-/api/links/:linkid
1000
+ def link(link_id)
1001
+ get("/api/links/#{link_id}")
1002
+ end
1003
+
1004
+ # Update a link
1005
+ #
1006
+ # @param link_id [String] The link's ID
1007
+ # @param params [Hash] Link parameters to update
1008
+ # @option params [String] :name Link name
1009
+ # @option params [String] :url Destination URL
1010
+ # @option params [String] :slug URL slug (minimum 8 characters)
1011
+ # @return [Hash] Updated link details
1012
+ # @see https://umami.is/docs/api/links#post-/api/links/:linkid
1013
+ def update_link(link_id, params = {})
1014
+ post("/api/links/#{link_id}", params)
1015
+ end
1016
+
1017
+ # Delete a link
1018
+ #
1019
+ # @param link_id [String] The link's ID
1020
+ # @return [Hash] Confirmation message
1021
+ # @see https://umami.is/docs/api/links#delete-/api/links/:linkid
1022
+ def delete_link(link_id)
1023
+ delete("/api/links/#{link_id}")
1024
+ end
1025
+
1026
+ # -------- Pixels endpoints --------
1027
+
1028
+ # Get all pixels
1029
+ #
1030
+ # @param params [Hash] Query parameters
1031
+ # @option params [String] :search Search text
1032
+ # @option params [Integer] :page Page number (default: 1)
1033
+ # @option params [Integer] :pageSize Number of results per page
1034
+ # @return [Hash] Paginated list of pixels
1035
+ # @see https://umami.is/docs/api/pixels#get-/api/pixels
1036
+ def pixels(params = {})
1037
+ get("/api/pixels", params)
1038
+ end
1039
+
1040
+ # Get a pixel by ID
1041
+ #
1042
+ # @param pixel_id [String] The pixel's ID
1043
+ # @return [Hash] Pixel details
1044
+ # @see https://umami.is/docs/api/pixels#get-/api/pixels/:pixelid
1045
+ def pixel(pixel_id)
1046
+ get("/api/pixels/#{pixel_id}")
1047
+ end
1048
+
1049
+ # Update a pixel
1050
+ #
1051
+ # @param pixel_id [String] The pixel's ID
1052
+ # @param params [Hash] Pixel parameters to update
1053
+ # @option params [String] :name Pixel name
1054
+ # @option params [String] :slug URL slug (minimum 8 characters)
1055
+ # @return [Hash] Updated pixel details
1056
+ # @see https://umami.is/docs/api/pixels#post-/api/pixels/:pixelid
1057
+ def update_pixel(pixel_id, params = {})
1058
+ post("/api/pixels/#{pixel_id}", params)
1059
+ end
1060
+
1061
+ # Delete a pixel
1062
+ #
1063
+ # @param pixel_id [String] The pixel's ID
1064
+ # @return [Hash] Confirmation message
1065
+ # @see https://umami.is/docs/api/pixels#delete-/api/pixels/:pixelid
1066
+ def delete_pixel(pixel_id)
1067
+ delete("/api/pixels/#{pixel_id}")
1068
+ end
1069
+
1070
+ # -------- Reports endpoints --------
1071
+
1072
+ # Get all reports
1073
+ #
1074
+ # @param params [Hash] Query parameters
1075
+ # @option params [String] :websiteId Website ID to filter by
1076
+ # @option params [String] :type Report type to filter by ('attribution', 'breakdown', 'funnel', 'goal', 'journey', 'retention', 'revenue', 'utm')
1077
+ # @option params [Integer] :page Page number (default: 1)
1078
+ # @option params [Integer] :pageSize Number of results per page
1079
+ # @return [Hash] Paginated list of reports
1080
+ # @see https://umami.is/docs/api/reports#get-/api/reports
1081
+ def reports(params = {})
1082
+ get("/api/reports", params)
1083
+ end
1084
+
1085
+ # Create a new report
1086
+ #
1087
+ # @param params [Hash] Report parameters
1088
+ # @option params [String] :websiteId Website ID (required)
1089
+ # @option params [String] :type Report type (required)
1090
+ # @option params [String] :name Report name (required)
1091
+ # @option params [String] :description Report description
1092
+ # @option params [Hash] :parameters Report-specific parameters
1093
+ # @return [Hash] Created report details
1094
+ # @see https://umami.is/docs/api/reports#post-/api/reports
1095
+ def create_report(params = {})
1096
+ post("/api/reports", params)
1097
+ end
1098
+
1099
+ # Get a report by ID
1100
+ #
1101
+ # @param report_id [String] The report's ID
1102
+ # @return [Hash] Report details
1103
+ # @see https://umami.is/docs/api/reports#get-/api/reports/:reportid
1104
+ def report(report_id)
1105
+ get("/api/reports/#{report_id}")
1106
+ end
1107
+
1108
+ # Update a report
1109
+ #
1110
+ # @param report_id [String] The report's ID
1111
+ # @param params [Hash] Report parameters to update
1112
+ # @option params [String] :name Report name
1113
+ # @option params [String] :description Report description
1114
+ # @option params [Hash] :parameters Report-specific parameters
1115
+ # @return [Hash] Updated report details
1116
+ # @see https://umami.is/docs/api/reports#post-/api/reports/:reportid
1117
+ def update_report(report_id, params = {})
1118
+ post("/api/reports/#{report_id}", params)
1119
+ end
1120
+
1121
+ # Delete a report
1122
+ #
1123
+ # @param report_id [String] The report's ID
1124
+ # @return [Hash] Confirmation message
1125
+ # @see https://umami.is/docs/api/reports#delete-/api/reports/:reportid
1126
+ def delete_report(report_id)
1127
+ delete("/api/reports/#{report_id}")
1128
+ end
1129
+
1130
+ # Run an attribution report
1131
+ #
1132
+ # @param params [Hash] Report parameters
1133
+ # @option params [String] :websiteId Website ID (required)
1134
+ # @option params [String] :startDate Start date in ISO 8601 format (required)
1135
+ # @option params [String] :endDate End date in ISO 8601 format (required)
1136
+ # @option params [String] :model Attribution model ('firstClick' or 'lastClick')
1137
+ # @option params [String] :type Attribution type ('path' or 'event')
1138
+ # @option params [Integer] :step Step number
1139
+ # @option params [Hash] :filters Filter criteria (path, referrer, title, query, browser, os, device, country, region, city, hostname, tag, segment, cohort)
1140
+ # @return [Hash] Attribution report data
1141
+ # @see https://umami.is/docs/api/reports#post-/api/reports/attribution
1142
+ def report_attribution(params = {})
1143
+ post("/api/reports/attribution", params)
1144
+ end
1145
+
1146
+ # Run a breakdown report
1147
+ #
1148
+ # @param params [Hash] Report parameters
1149
+ # @option params [String] :websiteId Website ID (required)
1150
+ # @option params [String] :startDate Start date in ISO 8601 format (required)
1151
+ # @option params [String] :endDate End date in ISO 8601 format (required)
1152
+ # @option params [Array<String>] :fields Fields to break down by (path, title, query, referrer, browser, os, device, country, region, city, hostname, tag, event)
1153
+ # @option params [Hash] :filters Filter criteria (path, referrer, title, query, browser, os, device, country, region, city, hostname, tag, segment, cohort)
1154
+ # @return [Hash] Breakdown report data
1155
+ # @see https://umami.is/docs/api/reports#post-/api/reports/breakdown
1156
+ def report_breakdown(params = {})
1157
+ post("/api/reports/breakdown", params)
1158
+ end
1159
+
1160
+ # Run a funnel report
1161
+ #
1162
+ # @param params [Hash] Report parameters
1163
+ # @option params [String] :websiteId Website ID (required)
1164
+ # @option params [String] :startDate Start date in ISO 8601 format (required)
1165
+ # @option params [String] :endDate End date in ISO 8601 format (required)
1166
+ # @option params [Array<Hash>] :steps Funnel steps (minimum 2, each with type and value)
1167
+ # @option params [Integer] :window Number of days between steps
1168
+ # @option params [Hash] :filters Filter criteria (path, referrer, title, query, browser, os, device, country, region, city, hostname, tag, segment, cohort)
1169
+ # @return [Hash] Funnel report data with conversion and drop-off rates
1170
+ # @see https://umami.is/docs/api/reports#post-/api/reports/funnel
1171
+ def report_funnel(params = {})
1172
+ post("/api/reports/funnel", params)
1173
+ end
1174
+
1175
+ # Run a goals report
1176
+ #
1177
+ # @param params [Hash] Report parameters
1178
+ # @option params [String] :websiteId Website ID (required)
1179
+ # @option params [String] :startDate Start date in ISO 8601 format (required)
1180
+ # @option params [String] :endDate End date in ISO 8601 format (required)
1181
+ # @option params [String] :type Goal type ('path' or 'event')
1182
+ # @option params [String] :value Goal value
1183
+ # @option params [Hash] :filters Filter criteria (path, referrer, title, query, browser, os, device, country, region, city, hostname, tag, segment, cohort)
1184
+ # @return [Hash] Goals report data
1185
+ # @see https://umami.is/docs/api/reports#post-/api/reports/goals
1186
+ def report_goals(params = {})
1187
+ post("/api/reports/goals", params)
1188
+ end
1189
+
1190
+ # Run a journey report
1191
+ #
1192
+ # @param params [Hash] Report parameters
1193
+ # @option params [String] :websiteId Website ID (required)
1194
+ # @option params [String] :startDate Start date in ISO 8601 format (required)
1195
+ # @option params [String] :endDate End date in ISO 8601 format (required)
1196
+ # @option params [Integer] :steps Number of steps (3-7)
1197
+ # @option params [String] :startStep Starting step path
1198
+ # @option params [String] :endStep Ending step path
1199
+ # @option params [Hash] :filters Filter criteria (path, referrer, title, query, browser, os, device, country, region, city, hostname, tag, segment, cohort)
1200
+ # @return [Hash] Journey report data showing user navigation paths
1201
+ # @see https://umami.is/docs/api/reports#post-/api/reports/journey
1202
+ def report_journey(params = {})
1203
+ post("/api/reports/journey", params)
1204
+ end
1205
+
1206
+ # Run a retention report
1207
+ #
1208
+ # @param params [Hash] Report parameters
1209
+ # @option params [String] :websiteId Website ID (required)
1210
+ # @option params [String] :startDate Start date in ISO 8601 format (required)
1211
+ # @option params [String] :endDate End date in ISO 8601 format (required)
1212
+ # @option params [String] :timezone Timezone (e.g., 'America/Los_Angeles') (required)
1213
+ # @option params [Hash] :filters Filter criteria (path, referrer, title, query, browser, os, device, country, region, city, hostname, tag, segment, cohort)
1214
+ # @return [Hash] Retention report data with day-based return rates
1215
+ # @see https://umami.is/docs/api/reports#post-/api/reports/retention
1216
+ def report_retention(params = {})
1217
+ post("/api/reports/retention", params)
1218
+ end
1219
+
1220
+ # Run a revenue report
1221
+ #
1222
+ # @param params [Hash] Report parameters
1223
+ # @option params [String] :websiteId Website ID (required)
1224
+ # @option params [String] :startDate Start date in ISO 8601 format (required)
1225
+ # @option params [String] :endDate End date in ISO 8601 format (required)
1226
+ # @option params [String] :timezone Timezone (e.g., 'America/Los_Angeles') (required)
1227
+ # @option params [String] :currency ISO 4217 currency code
1228
+ # @option params [Hash] :filters Filter criteria (path, referrer, title, query, browser, os, device, country, region, city, hostname, tag, segment, cohort)
1229
+ # @return [Hash] Revenue report data
1230
+ # @see https://umami.is/docs/api/reports#post-/api/reports/revenue
1231
+ def report_revenue(params = {})
1232
+ post("/api/reports/revenue", params)
1233
+ end
1234
+
1235
+ # Run a UTM report
1236
+ #
1237
+ # @param params [Hash] Report parameters
1238
+ # @option params [String] :websiteId Website ID (required)
1239
+ # @option params [String] :startDate Start date in ISO 8601 format (required)
1240
+ # @option params [String] :endDate End date in ISO 8601 format (required)
1241
+ # @option params [Hash] :filters Filter criteria (path, referrer, title, query, browser, os, device, country, region, city, hostname, tag, segment, cohort)
1242
+ # @return [Hash] UTM report data with campaign parameter breakdown
1243
+ # @see https://umami.is/docs/api/reports#post-/api/reports/utm
1244
+ def report_utm(params = {})
1245
+ post("/api/reports/utm", params)
496
1246
  end
497
1247
 
498
1248
  # -------- Sending stats endpoint --------
499
1249
 
500
- # Send an event
1250
+ # Send an event to Umami
1251
+ #
1252
+ # This method uses a separate connection that:
1253
+ # - Does NOT include Authorization header (not required for /api/send)
1254
+ # - Uses https://cloud.umami.is for Umami Cloud (different from the main API URL)
1255
+ # - Includes a User-Agent header (mandatory per API docs)
501
1256
  #
502
1257
  # @param payload [Hash] Event payload
503
- # @option payload [String] :hostname Name of host
504
- # @option payload [String] :language Language of visitor (ex. "en-US")
1258
+ # @option payload [String] :hostname Name of host (required)
1259
+ # @option payload [String] :language Language of visitor (e.g., "en-US")
505
1260
  # @option payload [String] :referrer Referrer URL
506
- # @option payload [String] :screen Screen resolution (ex. "1920x1080")
1261
+ # @option payload [String] :screen Screen resolution (e.g., "1920x1080")
507
1262
  # @option payload [String] :title Page title
508
- # @option payload [String] :url Page URL
509
- # @option payload [String] :website Website ID
1263
+ # @option payload [String] :url Page URL (required)
1264
+ # @option payload [String] :website Website ID (required)
510
1265
  # @option payload [String] :name Name of the event
1266
+ # @option payload [String] :tag Additional tag description
1267
+ # @option payload [String] :id Session identifier
511
1268
  # @option payload [Hash] :data Additional data for the event
512
- # @return [Hash] Response from the server
1269
+ # @param user_agent [String] Custom User-Agent header (defaults to "umami-ruby/VERSION")
1270
+ # @return [Hash] Response with cache, sessionId, and visitId
1271
+ # @note No authentication required. Uses https://cloud.umami.is for Umami Cloud.
513
1272
  # @see https://umami.is/docs/api/sending-stats
514
- def send_event(payload)
515
- post("/api/send", { type: "event", payload: payload })
1273
+ def send_event(payload, user_agent: default_user_agent)
1274
+ send_post("/api/send", { type: "event", payload: payload }, user_agent: user_agent)
516
1275
  end
517
1276
 
518
1277
 
519
1278
  private
520
1279
 
521
- def authenticate
522
- raise Umami::AuthenticationError, "Username and password are required for authentication" if @username.nil? || @password.nil?
523
-
524
- response = connection.post("/api/auth/login") do |req|
525
- req.body = { username: @username, password: @password }.to_json
526
- end
527
-
528
- data = JSON.parse(response.body)
529
- @access_token = data["token"]
530
- rescue Faraday::Error, JSON::ParserError => e
531
- raise Umami::AuthenticationError, "Authentication failed: #{e.message}"
532
- end
533
-
534
1280
  def get(path, params = {})
535
1281
  response = connection.get(path, params)
536
1282
  JSON.parse(response.body)
@@ -547,7 +1293,7 @@ module Umami
547
1293
 
548
1294
  def delete(path)
549
1295
  response = connection.delete(path)
550
- response.body == "ok" ? "ok" : JSON.parse(response.body)
1296
+ response.body == "ok" ? { "ok" => true } : JSON.parse(response.body)
551
1297
  rescue Faraday::Error => e
552
1298
  handle_error(e)
553
1299
  end
@@ -598,5 +1344,56 @@ module Umami
598
1344
  end
599
1345
  end
600
1346
 
1347
+ # -------- Send event helpers --------
1348
+
1349
+ # Default User-Agent for send requests
1350
+ #
1351
+ # @return [String] User-Agent string identifying this gem
1352
+ def default_user_agent
1353
+ "umami-ruby/#{Umami::VERSION}"
1354
+ end
1355
+
1356
+ # Determine the base URL for send requests
1357
+ #
1358
+ # For Umami Cloud, this returns https://cloud.umami.is (different from main API)
1359
+ # For self-hosted, this returns the configured uri_base
1360
+ #
1361
+ # @return [String] Base URL for send endpoint
1362
+ def send_uri_base
1363
+ cloud? ? Umami::Configuration::UMAMI_CLOUD_SEND_URL : @uri_base
1364
+ end
1365
+
1366
+ # Separate connection for send endpoint
1367
+ #
1368
+ # This connection:
1369
+ # - Does NOT include Authorization header (not required for /api/send)
1370
+ # - Includes User-Agent header (mandatory per API docs)
1371
+ # - Not memoized because user_agent can vary per call
1372
+ #
1373
+ # @param user_agent [String] User-Agent header value
1374
+ # @return [Faraday::Connection] Connection for send requests
1375
+ def send_connection(user_agent:)
1376
+ Faraday.new(url: send_uri_base) do |faraday|
1377
+ faraday.request :json
1378
+ faraday.response :raise_error
1379
+ faraday.adapter Faraday.default_adapter
1380
+ faraday.headers["User-Agent"] = user_agent
1381
+ faraday.options.timeout = request_timeout
1382
+ end
1383
+ end
1384
+
1385
+ # POST specifically for send endpoint (unauthenticated)
1386
+ #
1387
+ # @param path [String] API path
1388
+ # @param body [Hash] Request body
1389
+ # @param user_agent [String] User-Agent header value
1390
+ # @return [Hash] Parsed JSON response
1391
+ def send_post(path, body, user_agent:)
1392
+ response = send_connection(user_agent: user_agent).post(path, body.to_json)
1393
+ JSON.parse(response.body)
1394
+ rescue Faraday::Error => e
1395
+ handle_error(e)
1396
+ end
1397
+
601
1398
  end
602
1399
  end