Avo can code generate Avo Functions in Ruby for your server side tracking.
Avo functions usage consists of 4 steps.
To get the Avo generated Ruby file you must be a member of an Avo workspace with a Ruby source. Ask for an invite from a colleague or create a new workspace
TerminalCopy$$$npm install -g avoavo loginavo pull --branch my-branch-name
Learn more about the CLI here.
You can also download the file manually from your Avo workspace.
Import Avo from the generated file and initialize it by calling the init_avo
method before tracking
RubyCopy123require './avo.rb'Avo.init_avo(options: { env: :dev }, ...) # other parameters depend on your tracking plan setup
The actual parameters depend on your tracking plan setup, see the parameters explanation in the reference below.
Every event in your tracking plan, marked with the "Implement with Avo" checkbox, gets a function in the generated code, named according to the event name, in snake_case.
For example, if you have a "Signup Start" event defined like this in Avo:
You'll be able to call it like this from the generated code
RubyCopy1Avo.signup_start(referral: 'direct')
Notice, that you are not passing the System property with the call. System properties are defined on the init step and then automatically included with all events. You can update the system properties with
set_system_properties
function.
Use the Implementation status in your Avo workspace to verify that your implementation is correct.
RubyCopy1def self.init_avo(options:, [system_properties:], [mixpanel_destination:], [segment_destination:], [other_destination:], [logger: nil])
Initializes Avo, needs to be called before the tracking methods.
This method will call the make(env, apiKey)
callback in all the provided destination interfaces. It will also initialize the analytics SDKs of the legacy Avo Managed destinations.
options (Hash)
: a hash with :env symbol (:prod, :dev), :verbose (true, false)
system_properties (Hash)
: a Hash containing the system properties that should be sent with every event.
When you define system properties in your Avo workspace you set name and type - the keys in this hash should be the same as system properties, in snake_case, and you should provide corresponding types, can be string, int, long, float, bool and list.
[destination (object)]
: each destination you are sending events to gets a separate parameter in the init function with callbacks that the Avo generated code will trigger, unless you are using the legacy Avo managed destinations. Each method in the destination interface is directly mapped to the Actions attached to each event in Avo. Learn more about event Actions in this doc.
RubyCopy1234567891011121314151617181920212223242526# Example: Destination interface for the Mixpanel SDK. Replace the Mixpanel implementation with your own tracking SDK methodsclass CustomDestination# This method is optional, you can skip it if you've already initialized your Analytics SDKdef make(env:, api_key:)@tracker = Mixpanel::Tracker.new(api_key)enddef track_event(user_id:, event_name:, event_properties:)@tracker.track(user_id, event_name, event_properties)enddef log_page(user_id:, page_name:, event_properties:)# Note: Mixpanel does not provide a native method for page or screen tracking, so we send an event instead. Other SDKs may have a dedicated page tracking method.event_properties["Page Name"] = page_name@tracker.track(user_id, "Page Viewed", event_properties)enddef revenue(user_id:, amount:, event_properties:)@tracker.people.track_charge(user_id, amount, event_properties)enddef set_user_properties(user_id:, user_properties:)@tracker.people.set(user_id, user_properties)endend
To add the optional anonymousId
parameter to the callbacks in your workspace reach out to us.
Read more about the destination interface here.
RubyCopy1def self.set_system_properties(system_props)
A method to update system properties.
system_props (Hash)
: a Hash containing the system properties that should be sent with every event.
When you define system properties in your Avo workspace you set name and type - the keys in this dictionary should be the same as system properties, in snake_case, and you should provide corresponding types.
RubyCopy1def self.[your_event_name]([event_property_0:], [event_property_1:], ..., [user_property_0:], [user_property_1:], ..., [user_Id:], [anonymous_id:] })
Every event you define in your tracking plan in Avo gets a function named after the event in snake_case. The arguments of the function depend on how it's defined in your tracking plan.
event_property
: type defined in the Avo tracking plan, can be string, int, long, float, bool, array and any. The argument key is snake_case version of the property name defined in the Avo UI.
This is an event property that should be tracked with given event. Pass the value of the property to track here.
user_property
: type defined in the Avo tracking plan, can be string, int, long, float, bool, array and any. The argument key is snake_case version of the property name defined in the Avo UI.
This is a user property that should be updated with given event. Pass the value of the property to update here.
user_id
: string
added to all events, used to connect event to specific user, you have to either provide it or the anonymous_id
anonymous_id
: string, this argument is automatically added, used to track anonymous users
You can send your data using the Avo generated JavaScript code to any data destination that accepts custom events, including: