module BrazeAPI::Endpoints::Users::Track

Methods to call the users/track endpoint from a client instance

Constants

PATH

Public Instance Methods

track(args = {}) click to toggle source

The main method calling the endpoint. Called with an object containing multiple events and/or purchases and attributes.

# File lib/braze_api/endpoints/users/track.rb, line 13
def track(args = {})
  args[:events] = add_time_and_app_id(args[:events]) if args[:events]
  args[:purchases] = add_time_and_app_id(args[:purchases]) if args[:purchases]
  post(PATH, params: args)
end
track_attribute(attribute) click to toggle source

If you would like to track a single attribute object

# File lib/braze_api/endpoints/users/track.rb, line 30
def track_attribute(attribute)
  track(attributes: [attribute])
end
track_event(event) click to toggle source

If you would like to track a single event object

# File lib/braze_api/endpoints/users/track.rb, line 20
def track_event(event)
  track(events: [event])
end
track_purchase(purchase) click to toggle source

If you would like to track a single purchase object

# File lib/braze_api/endpoints/users/track.rb, line 25
def track_purchase(purchase)
  track(purchases: [purchase])
end

Private Instance Methods

add_time_and_app_id(tracking_objects) click to toggle source

Adds the time (mandatory for events and purchases) and the app id

# File lib/braze_api/endpoints/users/track.rb, line 37
def add_time_and_app_id(tracking_objects)
  tracking_objects.map { |obj| obj.merge!(time: Time.now.iso8601, app_id: app_id) }
end