---
title: "Send events from a Solar2D game"
description: "Add plugin.togohq to build.settings, call togo.init once in main.lua, and get installs, updates, opens and sessions on iOS and Android with no other code."
canonical: "https://www.togohq.ai/docs/solar2d"
applies_to: "sdk-solar2d 1.x"
updated: "2026-11-26T00:00:00Z"
---

# Send events from a Solar2D game

Add plugin.togohq to build.settings, call togo.init once in main.lua, and get installs, updates, opens and sessions on iOS and Android with no other code.

Use the Solar2D plugin, `plugin.togohq`, in a Solar2D game for iOS and Android. It is a Lua API
over the Togo [iOS](/docs/ios) and [Android](/docs/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](/docs/reference/sdk-solar2d).

## Add the plugin

In `build.settings`:

```lua
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:

```lua
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

```lua
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](/docs/guides/identify) and [Set person properties](/docs/guides/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

```lua
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](/docs/guides/consent) 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](/docs/verify).
