Module: Parse::API::Analytics

Included in:
Client
Defined in:
lib/parse/api/analytics.rb

Overview

Defines the Analytics interface for the Parse REST API

Instance Method Summary collapse

Instance Method Details

#send_analytics(event_name, metrics = {}, **opts) ⇒ Object

Send analytics data. Parse Server's default analyticsAdapter is a no-op: events POSTed here are accepted but not persisted and cannot be read back through Parse Server. Operators who wire in a custom adapter decide what (if anything) to do with each event, including whether to cap dimension count — the legacy parse.com eight-pair cap does NOT apply to Parse Server out of the box. If you need to read events back, persist them to a regular Parse::Object subclass instead.

Parameters:

  • event_name (String)

    the name of the event. Restricted to word characters, hyphens, and dots so the value cannot escape the /events/ path segment.

  • metrics (Hash) (defaults to: {})

    dimension pairs to attach to the event.

  • opts (Hash)

    additional options forwarded to Client#request (e.g. :session_token, :use_master_key). Analytics events are typically public-writable, but a session token can be threaded through for installations that require authentication on /events.

Raises:

  • (ArgumentError)

    when event_name is empty or contains characters outside [\w\-\.].

See Also:



29
30
31
32
33
34
35
36
37
# File 'lib/parse/api/analytics.rb', line 29

def send_analytics(event_name, metrics = {}, **opts)
  safe = event_name.to_s
  unless safe.match?(/\A[\w\-\.]+\z/)
    raise ArgumentError,
          "Parse::API::Analytics#send_analytics: event_name must contain only " \
          "word characters, hyphens, or dots (got #{event_name.inspect})"
  end
  request :post, "events/#{safe}", body: metrics, opts: opts
end