Collecting data with Trackers and Webhooks

  1. Home
  2. Docs
  3. Collecting data with Trackers and Webhooks
  4. Trackers – collecting data from your own applications
  5. Lua tracker
  6. Initialization

Initialization

Assuming you have completed the Lua Tracker Setup for your Lua project, you are now ready to initialize the Lua Tracker.

Requiring the module

Require the Lua Tracker”s module into your Lua code like so:

local snowplow = require( "snowplow" )

That’s it – you are now ready to initialize a tracker instance.

Creating a tracker

There are two different versions of the tracker constructor, depending on which type of collector you want to log events to.

If you are using a Cloudfront collector, use newTrackerForCf() to initialize your tracker instance. If you are using any other collector (e.g. the Clojure Collector or the Scala Stream Collector), then you should use newTrackerForUri().

Create a tracker logging to Cloudfront with newTrackerForCf()

You can initialize a tracker instance for a Cloudfront collector with:

local t = snowplow.newTrackerForCf( "{{CLOUDFRONT-SUBDOMAIN}}" )

So if your Cloudfront subdomain is d3rkrsqld9gmqf, you would write:

local t = snowplow.newTrackerForCf( "d3rkrsqld9gmqf" )

This completes the initialization of your tracker instance.

Create a tracker logging to a non-CloudFront collector using newTrackerForUri()

You can initialize a tracker instance for a non-Cloudfront collector with:

local t = snowplow.newTrackerForUri( "{{COLLECTOR-URI}}" )

So if your collector is available at “my-company.c.snplow.com”, you would write:

local t = snowplow.newTrackerForUri( "my-company.c.snplow.com" )

This completes the initialization of your tracker instance.

Creating multiple trackers

Each tracker instance is completely sandboxed, so you can create multiple trackers as you see fit.

Here is an example of instantiating two separate trackers:

local t1 = snowplow.newTrackerForCf( "d3rkrsqld9gmqf" ) t1:platform( "cnsl" ) t1:trackUnstructEvent( "save-game", { save_id = 23 }, 1369330092 ) local t2 = snowplow.newTrackerForUri( "cc-endpoint.mysite.com" ) t2:platform( "cnsl" ) t2:trackScreenView( "Game HUD", "23" ) t1:trackScreenView( "Test", "23" ) -- Back to first tracker