Use the Solar2D plugin, plugin.togohq, in a Solar2D game for iOS and Android. It is a Lua API
over the Togo iOS and Android SDKs, so the offline queue, sessions,
consent and the app lifecycle events are theirs. iOS 15 or later, Android 5.0 (API 21) or later.
Every function and option: Togo for Solar2D.
Add the plugin
In build.settings:
settings = {
plugins = {
["plugin.togohq"] = {
publisherId = "ai.togohq",
},
},
iphone = {
plist = {
MinimumOSVersion = "15.0",
},
},
android = {
minSdkVersion = "21",
},
}
Solar2D adds the plugin to your game when it builds for a device. The Android plugin brings the
Android SDK from https://maven.togohq.ai, so the build machine needs network access.
Set it up once, in main.lua
Use the test key (togo_pkt_…) while you develop, so verify_tracking sees the events from
your device, and the live key (togo_pkl_…) in the build you release:
local togo = require "plugin.togohq"
togo.init{
writeKey = "togo_pkt_…",
onError = function(e)
print(e.code, e.message)
end,
}
Call togo.init once, before anything else uses the plugin; a second call is ignored. No function
raises an error: a refused call logs one [togo] line saying why. In the Solar2D Simulator every
function does nothing and logs one line: events are sent from a device build only.
Track events and name the player
togo.track("level_complete", {
level = 3,
perfect = true,
})
-- After sign-in: your own account id.
togo.identify(account.id)
togo.setPersonProperties{
email = account.email,
}
-- At logout: a new anonymous visitor.
togo.reset()
A property value is a string, a finite number or a boolean; anything else is dropped from the event
and reported to onError as property_value_invalid. Pass the same id to identify that your
website and server use, so one person is one person on every platform. Never put an email address
or a name in an event property; they belong in setPersonProperties.
Identify people and Set person properties
explain both calls.
What the plugin sends on its own
| Event | When |
|---|---|
$app_installed |
The first launch of an install |
$app_updated |
The first launch after the game’s version or build changed |
$app_opened |
The game comes to the front: opened by the player, or brought back |
$session_started |
The first event of a session: after 30 minutes idle, or once a day has passed |
They are the iOS and Android SDKs’ own events, with the same properties. Every event carries the
game’s version and build, read as $app_version and $app_build, and the device’s OS, so any chart
can split by release and by platform.
In the first version of your game that adds the plugin, every existing player’s first launch sends
$app_installed, because there is no earlier install to find. Expect one spike of installs in that
release.
Ask for consent where you need it
togo.init{
writeKey = key,
consent = "pending",
}
-- When your consent screen resolves:
togo.setConsent("granted")
Under "pending" the plugin holds up to 100 events in memory and stores and sends nothing.
"granted" sends them; "denied" drops them and deletes what the plugin stored on the device.
Connect a consent banner explains the four states; whether your game needs
consent is your determination.
Check it works
Run a device build with the test key, play a level, and confirm the events arrived: Check that events arrive.