Class: Appwrite::Analytics

Inherits:
Service
  • Object
show all
Defined in:
lib/appwrite/services/analytics.rb

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ Analytics

Returns a new instance of Analytics.



5
6
7
# File 'lib/appwrite/services/analytics.rb', line 5

def initialize(client)
    @client = client
end

Instance Method Details

#create_annotation(property_id:, annotation_id:, date:, content:) ⇒ AnalyticsAnnotation

Create an annotation that marks a point in time on an analytics property's charts.

Parameters:

  • property_id (String) —

    Analytics property unique ID.

  • annotation_id (String) —

    Unique ID. Choose a custom ID or generate a random ID with ID.unique(). Max length is 36 chars.

  • date (String) —

    Point in time the annotation marks, in ISO 8601 format.

  • content (String) —

    Annotation text. Max length: 512 chars.

Returns:

  • (AnalyticsAnnotation)


261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
# File 'lib/appwrite/services/analytics.rb', line 261

def create_annotation(
    property_id:,
    annotation_id:,
    date:,
    content:
)
    if property_id.nil? || property_id == ''
        raise Appwrite::Exception.new('Missing required parameter: "propertyId"')
    end

    if annotation_id.nil?
        raise Appwrite::Exception.new('Missing required parameter: "annotationId"')
    end

    if date.nil?
        raise Appwrite::Exception.new('Missing required parameter: "date"')
    end

    if content.nil?
        raise Appwrite::Exception.new('Missing required parameter: "content"')
    end

    api_path = '/analytics/properties/{propertyId}/annotations'
        .gsub('{propertyId}', @client.encode_path(property_id))

    api_params = {
        annotationId: annotation_id,
        date: date,
        content: content,
    }

    api_headers = {
        "X-Appwrite-Project": @client.get_config('project'),
        "content-type": 'application/json',
        "accept": 'application/json',
    }

    @client.call(
        method: 'POST',
        path: api_path,
        headers: api_headers,
        params: api_params,
        response_type: Models::AnalyticsAnnotation
    )
end

#create_event(property_id:, name:, url:, domain: nil, referrer: nil, screen_width: nil, session_hash: nil, scroll_depth: nil, engagement_time: nil, props: nil, user_id: nil, ip: nil, user_agent: nil, interactive: nil) ⇒ Object

Send a tracking event from a browser, native app, or server-side SDK.

Parameters:

  • property_id (String) —

    Analytics property ID.

  • name (String) —

    Event name. "pageview" and "screen_view" are counted as views, every other name is a custom event.

  • url (String) —

    Full page URL or screen identifier.

  • domain (String) (defaults to: nil) —

    Hostname (e.g. example.com).

  • referrer (String) (defaults to: nil) —

    Referrer URL.

  • screen_width (Integer) (defaults to: nil) —

    Viewport width in CSS pixels.

  • session_hash (String) (defaults to: nil) —

    Optional session hash (provided by SDK).

  • scroll_depth (Integer) (defaults to: nil) —

    Scroll depth percentage 0-100.

  • engagement_time (Integer) (defaults to: nil) —

    Engagement time in seconds, 0-4294967295.

  • props (Array) (defaults to: nil) —

    Custom string properties as a flat key=value list (max 32 entries, alternating key,value).

  • user_id (String) (defaults to: nil) —

    Override user ID. Pass an opaque ID, not personal data such as an email. Requires API-key auth with analytics.write scope.

  • ip (String) (defaults to: nil) —

    Override IP address. Requires API-key auth with analytics.write scope.

  • user_agent (String) (defaults to: nil) —

    Override user agent. Requires API-key auth with analytics.write scope.

  • [] —

    interactive Whether this event is a visitor interaction that ends a bounce. Set false for telemetry such as heartbeats or background syncs. Defaults to true for custom events and false for the automatic engagement, scroll and app lifecycle events. Ignored for views.

Returns:

  • []



448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
# File 'lib/appwrite/services/analytics.rb', line 448

def create_event(
    property_id:,
    name:,
    url:,
    domain: nil,
    referrer: nil,
    screen_width: nil,
    session_hash: nil,
    scroll_depth: nil,
    engagement_time: nil,
    props: nil,
    user_id: nil,
    ip: nil,
    user_agent: nil,
    interactive: nil
)
    if property_id.nil? || property_id == ''
        raise Appwrite::Exception.new('Missing required parameter: "propertyId"')
    end

    if name.nil?
        raise Appwrite::Exception.new('Missing required parameter: "name"')
    end

    if url.nil?
        raise Appwrite::Exception.new('Missing required parameter: "url"')
    end

    api_path = '/analytics/properties/{propertyId}/events'
        .gsub('{propertyId}', @client.encode_path(property_id))

    api_params = {
        name: name,
        url: url,
        domain: domain,
        referrer: referrer,
        screenWidth: screen_width,
        sessionHash: session_hash,
        scrollDepth: scroll_depth,
        engagementTime: engagement_time,
        props: props,
        userId: user_id,
        ip: ip,
        userAgent: user_agent,
        interactive: interactive,
    }

    api_headers = {
        "X-Appwrite-Project": @client.get_config('project'),
        "content-type": 'application/json',
        "accept": 'application/json',
    }

    @client.call(
        method: 'POST',
        path: api_path,
        headers: api_headers,
        params: api_params,
    )
end

#create_property(property_id:, name:, domain: nil, enabled: nil, allowed_origins: nil, identify_users: nil, type: nil) ⇒ AnalyticsProperty

Create a new analytics property to track a website or application.

Parameters:

  • property_id (String) —

    Unique ID. Choose a custom ID or generate a random ID with ID.unique(). Max length is 36 chars.

  • name (String) —

    Human-readable name for this property.

  • domain (String) (defaults to: nil) —

    Primary domain to track (e.g. example.com). May be empty for mobile and agent properties.

  • [] —

    enabled Whether the property accepts events. Events sent to a disabled property are rejected as not found.

  • allowed_origins (Array) (defaults to: nil) —

    Allowed origins for tracking. Use ["*"] to allow all.

  • [] —

    identify_users Record the signed-in user's ID on events sent from a client session, so traffic can be broken down and counted by user. Off by default.

  • type (AnalyticsPropertyType) (defaults to: nil) —

    Kind of product this property tracks. Only changes which panels the dashboard shows; ingestion accepts the same events for every type.

Returns:

  • (AnalyticsProperty)


54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/appwrite/services/analytics.rb', line 54

def create_property(
    property_id:,
    name:,
    domain: nil,
    enabled: nil,
    allowed_origins: nil,
    identify_users: nil,
    type: nil
)
    if property_id.nil?
        raise Appwrite::Exception.new('Missing required parameter: "propertyId"')
    end

    if name.nil?
        raise Appwrite::Exception.new('Missing required parameter: "name"')
    end

    api_path = '/analytics/properties'

    api_params = {
        propertyId: property_id,
        name: name,
        domain: domain,
        enabled: enabled,
        allowedOrigins: allowed_origins,
        identifyUsers: identify_users,
        type: type,
    }

    api_headers = {
        "X-Appwrite-Project": @client.get_config('project'),
        "content-type": 'application/json',
        "accept": 'application/json',
    }

    @client.call(
        method: 'POST',
        path: api_path,
        headers: api_headers,
        params: api_params,
        response_type: Models::AnalyticsProperty
    )
end

#delete_annotation(property_id:, annotation_id:) ⇒ Object

Delete an analytics annotation.

Parameters:

  • property_id (String) —

    Analytics property unique ID.

  • annotation_id (String) —

    Annotation unique ID.

Returns:

  • []



398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
# File 'lib/appwrite/services/analytics.rb', line 398

def delete_annotation(
    property_id:,
    annotation_id:
)
    if property_id.nil? || property_id == ''
        raise Appwrite::Exception.new('Missing required parameter: "propertyId"')
    end

    if annotation_id.nil? || annotation_id == ''
        raise Appwrite::Exception.new('Missing required parameter: "annotationId"')
    end

    api_path = '/analytics/properties/{propertyId}/annotations/{annotationId}'
        .gsub('{propertyId}', @client.encode_path(property_id))
        .gsub('{annotationId}', @client.encode_path(annotation_id))

    api_params = {}

    api_headers = {
        "X-Appwrite-Project": @client.get_config('project'),
        "content-type": 'application/json',
        "accept": 'application/json',
    }

    @client.call(
        method: 'DELETE',
        path: api_path,
        headers: api_headers,
        params: api_params,
    )
end

#delete_property(property_id:) ⇒ Object

Delete an analytics property along with every event and session collected for it. This cannot be undone.

Parameters:

  • property_id (String) —

    Analytics property unique ID.

Returns:

  • []



187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
# File 'lib/appwrite/services/analytics.rb', line 187

def delete_property(
    property_id:
)
    if property_id.nil? || property_id == ''
        raise Appwrite::Exception.new('Missing required parameter: "propertyId"')
    end

    api_path = '/analytics/properties/{propertyId}'
        .gsub('{propertyId}', @client.encode_path(property_id))

    api_params = {}

    api_headers = {
        "X-Appwrite-Project": @client.get_config('project'),
        "content-type": 'application/json',
        "accept": 'application/json',
    }

    @client.call(
        method: 'DELETE',
        path: api_path,
        headers: api_headers,
        params: api_params,
    )
end

#get_annotation(property_id:, annotation_id:) ⇒ AnalyticsAnnotation

Get an analytics annotation by ID.

Parameters:

  • property_id (String) —

    Analytics property unique ID.

  • annotation_id (String) —

    Annotation unique ID.

Returns:

  • (AnalyticsAnnotation)


313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
# File 'lib/appwrite/services/analytics.rb', line 313

def get_annotation(
    property_id:,
    annotation_id:
)
    if property_id.nil? || property_id == ''
        raise Appwrite::Exception.new('Missing required parameter: "propertyId"')
    end

    if annotation_id.nil? || annotation_id == ''
        raise Appwrite::Exception.new('Missing required parameter: "annotationId"')
    end

    api_path = '/analytics/properties/{propertyId}/annotations/{annotationId}'
        .gsub('{propertyId}', @client.encode_path(property_id))
        .gsub('{annotationId}', @client.encode_path(annotation_id))

    api_params = {}

    api_headers = {
        "X-Appwrite-Project": @client.get_config('project'),
        "accept": 'application/json',
    }

    @client.call(
        method: 'GET',
        path: api_path,
        headers: api_headers,
        params: api_params,
        response_type: Models::AnalyticsAnnotation
    )
end

#get_property(property_id:) ⇒ AnalyticsProperty

Get an analytics property by ID.

Parameters:

  • property_id (String) —

    Analytics property unique ID.

Returns:

  • (AnalyticsProperty)


103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/appwrite/services/analytics.rb', line 103

def get_property(
    property_id:
)
    if property_id.nil? || property_id == ''
        raise Appwrite::Exception.new('Missing required parameter: "propertyId"')
    end

    api_path = '/analytics/properties/{propertyId}'
        .gsub('{propertyId}', @client.encode_path(property_id))

    api_params = {}

    api_headers = {
        "X-Appwrite-Project": @client.get_config('project'),
        "accept": 'application/json',
    }

    @client.call(
        method: 'GET',
        path: api_path,
        headers: api_headers,
        params: api_params,
        response_type: Models::AnalyticsProperty
    )
end

#list_annotations(property_id:, queries: nil, total: nil) ⇒ AnalyticsAnnotationList

List the annotations of an analytics property. Filter on date to fetch the annotations inside a chart's time range.

Parameters:

  • property_id (String) —

    Analytics property unique ID.

  • queries (Array) (defaults to: nil) —

    Array of query strings generated using the Query class provided by the SDK. Learn more about queries. Maximum of 100 queries are allowed, each 4096 characters long. You may filter on the following attributes: date

  • [] —

    total When set to false, the total count returned will be 0 and will not be calculated.

Returns:

  • (AnalyticsAnnotationList)


221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
# File 'lib/appwrite/services/analytics.rb', line 221

def list_annotations(
    property_id:,
    queries: nil,
    total: nil
)
    if property_id.nil? || property_id == ''
        raise Appwrite::Exception.new('Missing required parameter: "propertyId"')
    end

    api_path = '/analytics/properties/{propertyId}/annotations'
        .gsub('{propertyId}', @client.encode_path(property_id))

    api_params = {
        queries: queries,
        total: total,
    }

    api_headers = {
        "X-Appwrite-Project": @client.get_config('project'),
        "accept": 'application/json',
    }

    @client.call(
        method: 'GET',
        path: api_path,
        headers: api_headers,
        params: api_params,
        response_type: Models::AnalyticsAnnotationList
    )
end

#list_metrics(property_id:, queries: nil, interval: nil, dimensions: nil, prop_key: nil, date_range: nil, start_at: nil, end_at: nil, limit: nil, total: nil) ⇒ AnalyticsMetricList

Read analytics metrics (visitors, sessions, pageviews, events, bounceRate, …) for a property over a date range.

Three response shapes, chosen by dimensions[] and interval:

  • Neither: one row aggregating the whole window, with value and date null. Only this shape carries visits, bounceRate, visitDuration, viewsPerVisit, scrollDepth and engagementTime.
  • dimensions[]: one row per dimension value, ranked by visitors, with value set and date null.
  • interval: one row per time bucket in chronological order, with date set and value null.

pageviews is carried by the flat aggregate and by interval, but not by a breakdown.

userId and users cover identified traffic only: events sent with an API key's userId, or from a signed-in session on a property with identifyUsers on. A userId breakdown leaves out anonymous events; returned values are the project's user IDs.

Custom event props: dimensions[]=props ranks the prop keys seen in the window, and adding propKey ranks the values of that one key. queries[] filters on a prop's value with the props.<key> attribute, e.g. equal("props.plan", ["pro"]).

Combining dimensions[] with interval is not supported yet. queries[] filters the underlying events using standard Utopia query syntax.

Parameters:

  • property_id (String) —

    Analytics property unique ID.

  • queries (Array) (defaults to: nil) —

    Up to 10 filter queries in Utopia syntax. Allowed attributes: country, region, city, browser, browserVersion, operatingSystem, operatingSystemVersion, device, screenSize, referrerSource, channel, utmSource, utmMedium, utmCampaign, utmContent, utmTerm, page, hostname, trafficType, botName, botCategory, userId, eventName, and props.<key> for a custom prop. page, userId, eventName and props.<key> are only accepted alongside interval, or with a breakdown on a dimension other than entryPage, exitPage. Allowed methods: equal, notEqual, contains, startsWith, endsWith. Example: queries[]=equal("country", ["US"]).

  • interval (AnalyticsInterval) (defaults to: nil) —

    Time bucket size. Omit (null) for a flat aggregate over the whole window. Allowed: 1h, 1d, 1w, 1m.

  • dimensions (Array) (defaults to: nil) —

    Dimension to break the metrics down by. One at most for now; the parameter is a list so that cap can be raised without a breaking change. Allowed: country, region, city, browser, browserVersion, operatingSystem, operatingSystemVersion, device, screenSize, referrerSource, channel, utmSource, utmMedium, utmCampaign, utmContent, utmTerm, page, hostname, entryPage, exitPage, trafficType, botName, botCategory, userId, eventName, props.

  • prop_key (String) (defaults to: nil) —

    Custom prop key whose values to rank, with dimensions[]=props. Omit to rank the prop keys themselves.

  • date_range (String) (defaults to: nil) —

    Date range shorthand (e.g. 7d, 30d). Ignored for any bound you supply explicitly via startAt/endAt.

  • start_at (String) (defaults to: nil) —

    Explicit window start in ISO 8601. Defaults to endAt minus dateRange.

  • end_at (String) (defaults to: nil) —

    Explicit window end in ISO 8601. Defaults to the current time.

  • limit (Integer) (defaults to: nil) —

    Maximum number of ranked values to return.

  • [] —

    total When set to false, the total count returned will be 0 and will not be calculated.

Returns:

  • (AnalyticsMetricList)


549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
# File 'lib/appwrite/services/analytics.rb', line 549

def list_metrics(
    property_id:,
    queries: nil,
    interval: nil,
    dimensions: nil,
    prop_key: nil,
    date_range: nil,
    start_at: nil,
    end_at: nil,
    limit: nil,
    total: nil
)
    if property_id.nil? || property_id == ''
        raise Appwrite::Exception.new('Missing required parameter: "propertyId"')
    end

    api_path = '/analytics/properties/{propertyId}/metrics'
        .gsub('{propertyId}', @client.encode_path(property_id))

    api_params = {
        queries: queries,
        interval: interval,
        dimensions: dimensions,
        propKey: prop_key,
        dateRange: date_range,
        startAt: start_at,
        endAt: end_at,
        limit: limit,
        total: total,
    }

    api_headers = {
        "X-Appwrite-Project": @client.get_config('project'),
        "accept": 'application/json',
    }

    @client.call(
        method: 'GET',
        path: api_path,
        headers: api_headers,
        params: api_params,
        response_type: Models::AnalyticsMetricList
    )
end

#list_properties(queries: nil, search: nil, total: nil) ⇒ AnalyticsPropertyList

List analytics properties for the current project.

Parameters:

  • queries (Array) (defaults to: nil) —

    Array of query strings generated using the Query class provided by the SDK. Learn more about queries. Maximum of 100 queries are allowed, each 4096 characters long. You may filter on the following attributes: name, domain, enabled, type

  • search (String) (defaults to: nil) —

    Search term to filter your list results. Matches the property ID, name and domain. Max length: 256 chars.

  • [] —

    total When set to false, the total count returned will be 0 and will not be calculated.

Returns:

  • (AnalyticsPropertyList)


16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/appwrite/services/analytics.rb', line 16

def list_properties(
    queries: nil,
    search: nil,
    total: nil
)
    api_path = '/analytics/properties'

    api_params = {
        queries: queries,
        search: search,
        total: total,
    }

    api_headers = {
        "X-Appwrite-Project": @client.get_config('project'),
        "accept": 'application/json',
    }

    @client.call(
        method: 'GET',
        path: api_path,
        headers: api_headers,
        params: api_params,
        response_type: Models::AnalyticsPropertyList
    )
end

#update_annotation(property_id:, annotation_id:, date: nil, content: nil) ⇒ AnalyticsAnnotation

Update an analytics annotation. Only the attributes you pass are changed; omitted attributes keep their current value.

Parameters:

  • property_id (String) —

    Analytics property unique ID.

  • annotation_id (String) —

    Annotation unique ID.

  • date (String) (defaults to: nil) —

    Point in time the annotation marks, in ISO 8601 format.

  • content (String) (defaults to: nil) —

    Annotation text. Max length: 512 chars.

Returns:

  • (AnalyticsAnnotation)


354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
# File 'lib/appwrite/services/analytics.rb', line 354

def update_annotation(
    property_id:,
    annotation_id:,
    date: nil,
    content: nil
)
    if property_id.nil? || property_id == ''
        raise Appwrite::Exception.new('Missing required parameter: "propertyId"')
    end

    if annotation_id.nil? || annotation_id == ''
        raise Appwrite::Exception.new('Missing required parameter: "annotationId"')
    end

    api_path = '/analytics/properties/{propertyId}/annotations/{annotationId}'
        .gsub('{propertyId}', @client.encode_path(property_id))
        .gsub('{annotationId}', @client.encode_path(annotation_id))

    api_params = {
        date: date,
        content: content,
    }

    api_headers = {
        "X-Appwrite-Project": @client.get_config('project'),
        "content-type": 'application/json',
        "accept": 'application/json',
    }

    @client.call(
        method: 'PATCH',
        path: api_path,
        headers: api_headers,
        params: api_params,
        response_type: Models::AnalyticsAnnotation
    )
end

#update_property(property_id:, name: nil, domain: nil, enabled: nil, allowed_origins: nil, identify_users: nil, type: nil) ⇒ AnalyticsProperty

Update an analytics property. Only the attributes you pass are changed; omitted attributes keep their current value.

Parameters:

  • property_id (String) —

    Analytics property unique ID.

  • name (String) (defaults to: nil) —

    Human-readable name for this property.

  • domain (String) (defaults to: nil) —

    Primary domain to track (e.g. example.com). Pass an empty string to clear it.

  • [] —

    enabled Whether the property accepts events. Events sent to a disabled property are rejected as not found.

  • allowed_origins (Array) (defaults to: nil) —

    Allowed origins for tracking. Use ["*"] to allow all. On a property linked to a site, Appwrite manages this list: it is rewritten from the site's production domains whenever they change.

  • [] —

    identify_users Record the signed-in user's ID on events sent from a client session, so traffic can be broken down and counted by user.

  • type (AnalyticsPropertyType) (defaults to: nil) —

    Kind of product this property tracks. Only changes which panels the dashboard shows; stored events are kept.

Returns:

  • (AnalyticsProperty)


141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
# File 'lib/appwrite/services/analytics.rb', line 141

def update_property(
    property_id:,
    name: nil,
    domain: nil,
    enabled: nil,
    allowed_origins: nil,
    identify_users: nil,
    type: nil
)
    if property_id.nil? || property_id == ''
        raise Appwrite::Exception.new('Missing required parameter: "propertyId"')
    end

    api_path = '/analytics/properties/{propertyId}'
        .gsub('{propertyId}', @client.encode_path(property_id))

    api_params = {
        name: name,
        domain: domain,
        enabled: enabled,
        allowedOrigins: allowed_origins,
        identifyUsers: identify_users,
        type: type,
    }

    api_headers = {
        "X-Appwrite-Project": @client.get_config('project'),
        "content-type": 'application/json',
        "accept": 'application/json',
    }

    @client.call(
        method: 'PATCH',
        path: api_path,
        headers: api_headers,
        params: api_params,
        response_type: Models::AnalyticsProperty
    )
end