Avo
  • About
  • Plans
  • Docs
  • Blog
  • Jobs
  • Login
  • Get started
  • About
  • Plans
  • Docs
  • Blog
  • Jobs
  • Login
  • Get started

Setting up Custom Destinations

Sometimes the best way to integrate Avo is through a custom destination. For example:

  • When using custom pipelines
  • When sending data to analytics platforms through an API (not using their SDK)
  • When using a combination of a programming language and analytics destination not yet directly supported by Avo

Please contact us if you are unsure of what is the best solution for you or if there are any analytics destinations you'd like to see supported in Avo.

To get started using a custom destination you do the following:

  1. Create a Custom Destination in the Connections tab

  2. Pull the updated code by doing avo pull in the Avo CLI

  3. Initialize Avo with a custom destination

  4. Fill in the empty methods for sending the data to your analytics destination

Custom Destinations overview

We will be referencing Avo functions, events, actions and other Avo concepts in this document. Please read the Tracking Plan doc to get familiar with Avo concepts.

With a custom destination you'll get access to callback methods for Avo actions. The Avo generated code triggers the callbacks when corresponding Avo functions are called.

Callback methods

  • make: Triggered during Avo initialization. Here you will usually initialize an analytics library with a development or production key based on the env parameter.

  • logEvent: All your analytics events are managed in the Avo dashboard. Each event gets a generated Avo function. Avo events can have a Log Event action attached. This callback is triggered when an Avo function with Log Event action is called. Here you perform the actual event tracking, calling the track/log methods of the analytics SDK. Event name and event properties are provided as parameters.

  • identify: You can add the Identify User action to an event in the Avo dashboard. When calling an Avo function that includes the Identify User action you'll need to provide a user ID. Calling an Avo function that has the Identify User action will trigger this callback. The main use cases are signup and login. Here you would pass the user ID to the analytics library for it to create a new user or attach a session to an existing user.

  • unidentify: If you call an Avo function with the Unidentify User action, this callback will be triggered. Here you would call an analytics SDK method to detach subsequent actions from the currently identified user.

  • setUserProperties: You can add user properties to events in the Avo dashboard. When an Avo function with attached user properties is called, this callback is triggered. Here you would attach user properties to the currently identified user in your analytics platform.

Initialization instructions

Below are instructions on how to initialize Avo with a custom destination for each of the supported languages:


WebMobileBackendGame Engines

Web

JavaScript

Import the Avo library into your code:

import Avo from './Avo';
// An object representing your custom pipeline
// that you pass into initAvo():
var customAvoLogger = {
make: function(env) {
// TODO implement
},
logEvent: function(eventName, eventProperties) {
// TODO implement
},
setUserProperties: function(userId, userProperties) {
// TODO implement
},
identify: function(userId) {
// TODO implement
},
unidentify: function() {
// TODO implement
}
};

Call the initAvo function:

Avo.initAvo({env: 'dev'}, {}, {}, customAvoLogger);

TypeScript

import Avo from './Avo';
// An object representing your custom pipeline
// that you pass into initAvo():
let customAvoLogger = {
make: function(env) {
// TODO implement
},
logEvent: (eventName, eventProperties) => {
// TODO implement
},
setUserProperties: (userId, userProperties) => {
// TODO implement
},
identify: userId => {
// TODO implement
},
unidentify: () => {
// TODO implement
}
};

Call the initAvo function:

Avo.initAvo({env: Avo.AvoEnv.Dev}, {}, customAvoLogger);

Mobile

iOS

Objective-C

import Avo
// An object representing your custom pipeline
// that you pass into initAvo():
@interface CustomAvoLogger : NSObject <AVOCustomDestination>
@end
@implementation CustomAvoLogger : NSObject
- (void)make:(AVOEnv)avoEnv
{
// TODO implement
}
- (void)logEvent:(nonnull NSString*)eventName withEventProperties:(nonnull NSDictionary*)eventProperties
{
// TODO implement
}

Call the initAvo function:

CustomAvoLogger * customAvoLogger = [[CustomAvoLogger alloc] init];
[Avo initAvoWithEnv:AVOEnvDev
customDestination:customAvoLogger];

Swift

Import the Avo library into your code:

import Avo
// An object representing your custom pipeline
// that you pass into initAvo():
class CustomAvoLogger : AvoCustomDestination {
   func make(env: AvoEnv) {
       // TODO implement
   }
   
   func logEvent(eventName: String, eventProperties: [String : Any]) {
       // TODO implement
   }
   
   func setUserProperties(userId: String, userProperties: [String : Any]) {
       // TODO implement
   }
   
   func identify(userId: String) {
       // TODO implement
   }
   
   func unidentify() {
       // TODO implement
   }
}

Call the initAvo function:

func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
Avo.initAvo(env: .dev, customDestination: CustomAvoLogger())
}

Where customDestination is the name of the destination in Avo.

Android

Java

Import the Avo library into your code:

import Avo

Call the initAvo() function:

Avo.initAvo(application, context, Avo.AvoEnv.DEV, new Avo.ICustomDestination() {
public void make(Avo.AvoEnv env) {
// TODO implement
}
public void logEvent(String eventName, Map<String, Object> eventProperties) {
// TODO implement
}
public void setUserProperties(String userId, Map<String, Object> userProperties) {
// TODO implement
}
public void identify(String userId) {
// TODO implement
}
public void unidentify() {
// TODO implement
}
});

Kotlin

import Avo

Call the initAvo function:

Avo.initAvo(application=application, context=this, env=AvoEnv.DEV, customDestination=object : ICustomDestination {
override fun make(env: AvoEnv) {
// TODO implement
}
override fun logEvent(eventName: String, eventProperties: Map<String, *>) {
// TODO implement
}
override fun setUserProperties(userId: String, userProperties: Map<String, *) {
// TODO implement
}
override fun identify(userId: String) {
// TODO implement
}
override fun unidentify() {
// TODO implement
}
})

Backend

Node JS

JavaScript

Import the Avo library into your code:

var Avo = require('./Avo.js');
// An object representing your custom pipeline
// that you pass into initAvo():
var customAvoLogger = {
logEvent: function(userId, eventName, eventProperties) {
// TODO implement
},
setUserProperties: function(userId, userProperties) {
// TODO implement
}
};

Call the initAvo() function:

Avo.initAvo({env: 'dev'}, {}, {}, customAvoLogger);

By passing in the customAvoLogger object, its logEvent() function can be used to deliver an event to any custom destination or pipeline.

TypeScript

import Avo from './Avo';
// An object representing your custom pipeline
// that you pass into initAvo():
let customAvoLogger = {
logEvent: function(userId, eventName, eventProperties) {
// TODO implement
},
setUserProperties: function(userId, userProperties) {
// TODO implement
}
};

Call the initAvo function:

Avo.initAvo({env: Avo.AvoEnv.Dev}, {}, customAvoLogger);

Java

Import the Avo library into your code:

import Avo

Call the initAvo() function:

Avo.initAvo(Avo.AvoEnv.DEV, new Avo.ICustomDestination() {
public void make(Avo.AvoEnv env) {
// TODO implement
}
public void logEvent(String anonymousId, String userId, String eventName, Map<String, Object> eventProperties) {
// TODO implement
}
public void setUserProperties(String userId, Map<String, Object> userProperties) {
// TODO implement
}
});

PHP

require_once './Avo';
// An object representing your custom pipeline
// that you pass into initAvo():
class CustomAvoLogger {
public function make($env) {
// TODO implement
}
public function logEvent($userId, $eventName, $eventProperties) {
// TODO implement
}
public function setUserProperties($userId, $userProperties) {
// TODO implement
}
}

Call the initAvo function:

Avo::initAvo([
'env' => 'dev',
'customDestinationInstance' => new CustomAvoLogger,
]);

Python

Import the Avo library into your code:

from __future__ import print_function
import avo
# An object representing your custom pipeline
# that you pass into init_avo():
class CustomAvoLogger(object):
    def __init__(self):
        self.env = None
    def make(self, env):
pass
    def track_event(self, user_id, event_name, event_properties):
pass
    def set_user_properties(self, user_id, user_properties):
pass

Call the init_avo() function:

avo.init_avo(options={'env': 'dev'}, custom_destination=CustomAvoLogger())

where custom_destination is the name of the custom destination in Avo.

Ruby

import Avo
// An object representing your custom pipeline
// that you pass into initAvo():
class CustomAvoLogger
def make(env:)
# TODO implement
end
def track_event(anonymous_id:, user_id:, event_name:, event_properties:)
# TODO implement
end
def set_user_properties(anonymous_id:, user_id:, user_properties:)
# TODO implement
end
end

Call the initAvo function:

Avo.init_avo(options: {:env => :dev}, custom_destination: CustomAvoLogger.new)

Game Engines

Unity (C#)

using Avo;

Implement the custom destination:

class CustomAvoLogger : Avo.IDestination {
public void Make(Avo.AvoEnv env) {
// TODO implement
}
public async Task LogEvent(string eventName, IDictionary<string, object> eventProperties) {
// TODO implement
}
public async Task SetUserProperties(string userId, IDictionary<string, object> userProperties) {
// TODO implement
}
public async Task Identify(string userId) {
// TODO implement
}
public async Task Unidentify() {
// TODO implement
}
}

Call the initAvo function:

Avo.initAvo(env=Avo.AvoEnv.Dev, customDestination=new CustomAvoLogger());