-- build.settings
plugins = {
["plugin.togohq"] = {
publisherId = "ai.togohq",
},
},
A Lua API over the iOS SDK and the
Android SDK: iOS 15 or later, Android 5.0 (API 21) or later. Every
function is on the table require "plugin.togohq" returns, called with a dot, and never waits on
the network. No function raises an error: a refused call logs one [togo] … line saying why. A
guide to using it: Send events from a Solar2D game.
In the Solar2D Simulator every function does nothing and logs one line; events are sent from a device build only.
togo.init(options)
local togo = require "plugin.togohq"
togo.init{
writeKey = "togo_pkt_…",
}
Call it once, in main.lua, before anything else uses the plugin. A second call is ignored and
logged; the first configuration stands. A call made before init does nothing, and the first one
logs a line. Use the test key while you develop, so verify_tracking sees your device’s events,
and the live key in the build you release.
init sends the launch’s $app_installed or $app_updated. It starts no session: the game coming
to the front does, with $session_started and $app_opened.
Options
| Option | Type | Default | What it does |
|---|---|---|---|
writeKey |
string | — | Required. togo_pkt_… (test) or togo_pkl_… (live). A malformed key sends nothing |
endpoint |
string | https://in.togohq.ai |
Where events are sent |
sessionTimeoutSeconds |
number | 1800 (30 min) |
Seconds of inactivity that end a session, rounded up to a whole second. 0 or less turns sessions off: no sessionId is sent |
consent |
string | "notRequired" |
The starting consent state. "pending" holds events in memory until "granted" |
consentBufferMaxEvents |
number | 100 |
Events held while consent is "pending"; past it, the oldest are dropped and reported |
defaultProperties |
table | none | Properties on every togo.track() event, such as { store = "apple" } |
appVersion |
string | the app’s own | Your release number, read as $app_version. Set it when the app’s version is not it |
appBuild |
string | the app’s own | Your build number, read as $app_build. Set it when the app’s build is not it |
onError |
function | none | Called for every event, or part of one, that will not be recorded. See onError |
An option that is not on this list, or has the wrong type, is ignored with a log line. A session also ends after 24 hours, whatever the timeout.
togo.track(eventName, properties)
togo.track("level_complete", {
level = 3,
perfect = true,
})
A property value is a string, a finite number or a boolean; a whole number is sent as an integer.
A table, a function, NaN or an infinity is dropped from the event, which is still sent, and
reported as property_value_invalid. Names and strings are UTF-8 text: one cut in the middle of a
character, as string.sub can, is dropped the same way, a name as property_name_invalid. An event
name that is not text sends nothing. The name is stored exactly as you send it; the rules for
names, long values and how many properties fit are the
iOS and
Android SDKs’. Never put an email address, a name or text a player
typed in an event property: they belong in setPersonProperties.
togo.identify(userId)
togo.identify(account.id)
Call it at sign-in with your own account id — the same one your website and server use, never an
email address. The same id again does nothing; a different id first does what reset does. An
empty id, one that is not a string, or one over 128 characters is refused as user_id_invalid.
Identify people explains how one person is followed across platforms.
togo.setPersonProperties(update)
togo.setPersonProperties{
email = account.email,
set = { plan = "pro" },
}
email and name set the reserved person properties $email and $name, and false removes
the value. set, setOnce and unset take your own keys, as in
Set person properties; unset is a list of names. A field you
leave out changes nothing.
togo.reset()
Call it at logout. The device gets a new anonymous visitor and a new session; the device id stays.
togo.setConsent(state) and togo.getConsent()
togo.setConsent("granted")
Four states: "notRequired", "pending", "granted" and "denied". setConsent can be called
at any time and as often as you like. "granted" after "pending" sends what was held;
"denied" drops it and deletes everything the plugin stored on the device. getConsent() returns
the current state. Connect a consent banner explains the four states.
togo.getAnonymousId(), togo.getDeviceId(), togo.getSessionId()
Each returns the current id, or nil before the first event consent permits; getSessionId() is
also nil while there is no session. They never create an id. Pass getDeviceId() to
verify_tracking as filter.deviceId to check the events your device sent.
togo.flush(callback)
togo.flush(function()
print("sent")
end)
Sends what is queued now. The callback is optional; it runs once, on the Lua thread, after the
attempt — before togo.init too, when there is nothing to send. An event that could not be sent
stays queued and is retried.
onError
togo.init{
writeKey = key,
onError = function(e)
print(e.code, e.message)
end,
}
Pass it on to the error reporting your game already uses. It is called once for every event that
will not be recorded, or value dropped or cut from one — in a release build as well as while you
develop. Never for consent "denied". It runs on the Lua thread, after the call that caused it has
returned. It receives a table: code, message (what the log shows, without [togo] ),
eventIds, eventName and property (the property’s name when the report is about one, never
its value). The codes are the browser SDK’s. Treat a code
you do not recognise as a lost event.
Delivery
Events wait on the device while it is offline and are sent when it reconnects; each keeps the time it happened and the same event id across attempts. How many wait, and for how long: Limits.