As a lightweight, easily-embeddable scripting language, Lua is available in a huge number of different computing environments and platforms, from World of Warcraft through OpenResty to Adobe Lightroom. And now, the Snowplow Lua Tracker lets you collect event data from these Lua-based applications, Lua web servers/frameworks, or from the Lua scripting layer within your games or apps - here’s a taster:
We are hugely excited about our new event tracker for Lua. The first analytics tracker ever released for the Lua language, SnowplowTracker continues Snowplow’s push into the tracking and analysis of non-Web events. Moreover, as part of our commitment to High-Fidelity Analytics, this tracker:
- Is our first to include a full suite of unit and integration tests, built using the excellent Busted
- Uses contracts-style argument validation throughout, to prevent incorrectly-structured events from being sent to Snowplow
After the jump we will cover:
The Lua Tracker supports three types of event:
trackStructEvent()- for tracking Google Analytics-style custom structured events with five fields (category, action, label, property, value)
trackUnstructEvent()- for tracking Mixpanel-style custom unstructured events, consisting of an event name plus event properties in a Lua table
trackScreenView()- for tracking views of individual screens within a game, app or similar
Please note that currently only
trackStructEvent() is supported within the Snowplow ETL and Redshift table definition; adding support for unstructured events and screen views is on our roadmap.
Using the SnowplowTracker from Lua is really simple.
First require the library and instantiate a new tracker:
You can adjust the default configuration if you like:
Add any additional information about the app, user or device that you know:
Now you are ready to track your events:
And that’s it!
To read through the complete API for this Lua event tracker, please see the Lua Tracker page on the Snowplow wiki.
To check out the code itself, please see our snowplow-lua-tracker repository in GitHub.