Capture · Android / iOS Reference

Below is the list of all methods available in the OSB tracker for Android.

They are described in more detail below.

osb.create(...)

Creates an instance of a tracker. When you create a tracker you should also specify configuration parameters like the URL of the tracker and the account ID. An instance of a tracker should be created as part of the start-up code of the mobile app.

Usage

import OSB

let osb = OSB.instance
osb.create(accountId: String, trackerUrl: String)
osb.create(accountId: String, trackerUrl: String, siteId: String)
import com.onesecondbefore.tracker.OSB;

// Add this code to your app's initialization code
OSB osb = OSB.getInstance();
osb.create(Context context, String accountId, String trackerUrl);
osb.create(Context context, String accountId, String trackerUrl, String siteId);

Parameters

parameter nametyperequireddescription
contextContextAndroid onlyContext / Activity.
accountIdstringyesAccount id which specifies where your hits will be stored.
trackerUrlstringyesURL of the tracker used by the app
siteIdstringnoOptional identifier used to group hits together

Examples

// Minimal configuration for account account. The siteId will be development
let osb = OSB.instance
osb.create(accountId: "account", trackerUrl: "https://g.ab21.xyz")

// Creates a tracker for account with siteId mysite.app:
let osb = OSB.instance
osb.create(accountId: "account", trackerUrl: "https://g.ab21.xyz",
    siteId: "mysite.app")
// Minimal configuration for account account.
import com.onesecondbefore.tracker.OSB;

// this is Context / Activity
OSB osb = OSB.getInstance();
osb.create(this, "development", "https://g.ab21.xyz");

// Creates a tracker with site-id specified:
OSB osb = OSB.getInstance();
osb.create(this, "account", "https://g.ab21.xyz", "mysite.app");

osb.send(...)

Sends an event hit to the capture server.

Usage

let osb = OSB.instance
osb.send(type: OSBEventType, subtype: String, data: [String: Any])
OSB osb = OSB.getInstance(); 
osb.send(OSB.EventType type, String subtype, Map<String, Object> data);

Parameters

parameter nametyperequireddescription
typeenumyesSpecifies the type to send. The type will be written in column hit_type, except for 'action', where sub_type will be used. See below for the supported types
subtypestringyes if type == "action"You can choose an action from the ga() command queue (detail, add, remove, checkout, checkout_option, purchase, refund or promo_click), or use your own action as long as they only contain letters, numbers and/or underscores. The chosen subtype will be placed in the hit_type column.
dataMap or DictionarynoContains additional type specific data.

Type overview

Below types are defined in the enum OSB.EventType (Android) or OSBEventType (iOS).

typedescription
ACTIONtracks an action. If you choose action, you must define a subtype, column hit_type will contain the value of the subtype.
EVENTtracks an event, column hit_type will contain 'event'.
IDStracks identifiers.
PAGEVIEWtracks a pageview, column hit_type will contain 'pageview'. To be used if your app's navigation structure is similar to the website, e.g. a news app.
SCREENVIEWtracks a screenview, column hit_type will contain 'screenview'.

Examples

let data = [
    "category": "Video",
    "action": "start",
    "label": "Funny cat movie"
]
let osb = OSB.instance
osb.send(type: OSBEventType.event, subtype: "", data: data)
// or use
osb.sendEvent("Video", "start", "Funny cat movie");
OSB osb = osb.getInstance();
Map<String, Object> data = new HashMap<>();
data.put("category", "Video");
data.put("action", "start");
data.put("label", "Funny cat movie");
osb.send(OSB.EventType.EVENT, null, data);
// or use
osb.sendEvent("Video", "start", "Funny cat movie");

osb.sendPageView(...)

Sends a pageview hit to the capture server. Pageviews are a specific kind of event with a number of fixed parameters.

Usage

let osb = OSB.instance
osb.sendPageView(url: String)
osb.sendPageView(url: String, title: String)
osb.sendPageView(url: String, title: String, referrer: String)
osb.sendPageView(url: String, title: String, referrer: String, data: [String: Any])
OSB osb = OSB.getInstance();
osb.sendPageView(String url);
osb.sendPageView(String url, String title);
osb.sendPageView(String url, String title, String referrer);
osb.sendPageView(String url, String title, String referrer, Map<String, Object> data);

Parameters

parameter nametyperequireddescription
urlstringyesSpecifies the URL of the screen shown in the app as if it matches the website navigation structure
titlestringnoTitle of this page / screen
referrerstringnoName of previous page / screen. Used for creating journeys through the app.
dataMap or DictionarynoContains additional type specific data.

Examples

Sends a pageview:

let osb = OSB.instance
osb.sendPageView("https://mysite.app/page/subpage", "Page Title")
OSB osb = osb.getInstance();
osb.sendPageView("https://mysite.app/page/subpage", "Page Title");

osb.sendScreenView(...)

Sends a screenview hit to the capture server. Screenviews are a specific kind of event with a number of fixed parameters.

Usage

let osb = OSB.instance
osb.sendScreenView(name: String)
osb.sendScreenView(name: String, data: [String: Any])
OSB osb = OSB.getInstance();
osb.sendScreenView(String name);
osb.sendScreenView(String name, Map<String, Object> data);

Parameters

parameter nametyperequireddescription
namestringyesName of the screen
dataMap or DictionarynoContains additional type specific data.

Examples

Sends a screenview:

let osb = OSB.instance
osb.sendScreenView("listing")
OSB osb = osb.getInstance();
osb.sendPageView("listing");

osb.set(...)

Sets additional properties in the payload. The payload will not be sent after a set command. Only a subsequent 'send' will send the hit.

Usage

let osb = OSB.instance
osb.set(name: String, data: [String: Any])
osb.set(data: [String: Any])
OSB osb = OSB.getInstance();
osb.set(String name, Map data);
osb.set(Map data);

Parameters

nametyperequireddescription
namestringnoName of object used to group additional data under in the JSON payload. If no specified the data will be stored under the hit itself.
dataMap or DictionaryyesA Map (Android) or Dictionary (iOS) with additional data to store.

Examples

let osb = OSB.instance
osb.set("ids", data: ["username": "john.doe@example.com"])

let osb = OSB.instance
osb.set(["page_id": "123456", "other_id": "98765"])
Map data = new HashMap<>();
data.put("username", "john.doe@example.com");
OSB osb = OSB.getInstance();
osb.set("ids", data);

Map data = new HashMap<>();
data.put("page_id", "123456");
data.put("other_id", "98765");
OSB osb = OSB.getInstance();
osb.set(data);
This website uses cookies to ensure you get the best personal experience.