Skip to main content

Quick Start Guide

caution
You are reading documentation for an outdated version. Here’s the latest one!

Installation​

The iOS Tracker SDK can be installed using various dependency managers.

Swift Package Manager (Recommended)

To install Snowplow Tracker with SPM:

  1. In Xcode, select File > Swift Packages > Add Package Dependency.
  2. Add the url where to download the library: https://github.com/snowplow/snowplow-objc-tracker

Cocoapods

To install Snowplow Tracker with Cocoapods:

  1. Make sure that Cocoapods is installed on your system and correctly configured for your app.
  2. Add the iOS Tracker SDK among the dependencies of your Podfile:
   pod 'SnowplowTracker', '~> 2.0'
  1. Run the command pod install to add the tracker to your app project.

Carthage

To install Snowplow Tracker with Carthage:

  1. Make sure that Carthage is installed on your system and correctly configured for your app.
  2. Add the iOS Tracker SDK among the dependencies of your Cartfile:
   github "snowplow/snowplow-objc-tracker" ~> 2.0
  1. Run the command carthage update and drag the appropriate frameworks from the Carthage/build folder to your app project.

Supported System Version

The iOS Tracker SDK supports iOS 9.0+, macOS 10.9+, tvOS 9.0+ and watchOS 2.0+

Instrumentation​

Once the tracker SDK is correctly set as a dependency in your app project you have to instrument the tracker:

  1. In your application delegate AppDelegate.swift add import SnowplowTracker.
  2. In the application(_:didFinishLaunchingWithOptions:) method, set up the SDK as follows:
   let tracker = Snowplow.createTracker(namespace: "appTracker", endpoint: COLLECTOR_URL, method: .post)
  1. It creates a tracker instance which can be used to track events like this:
   let event = Structured(category: "Category_example", action: "Action_example")
tracker.track(event)

If you prefer to access the tracker when the reference is not directly accessible, you can use the defaultTracker :

   Snowplow.defaultTracker().track(event)

The tracker has a default configuration where some settings are enabled by default:

  • session tracking
  • screen tracking
  • platform contexts (mobile specific context fields)

You can override the default configuration with a fine grained configuration when you create the tracker:

let networkConfig = NetworkConfiguration(endpoint: COLLECTOR_URL, method: .post)
let trackerConfig = TrackerConfiguration()
.base64Encoding(false)
.sessionContext(true)
.platformContext(true)
.lifecycleAutotracking(true)
.screenViewAutotracking(true)
.screenContext(true)
.applicationContext(true)
.exceptionAutotracking(true)
.installAutotracking(true)
let sessionConfig = SessionConfiguration(
foregroundTimeout: Measurement(value: 30, unit: .minutes),
backgroundTimeout: Measurement(value: 30, unit: .minutes)
)
Snowplow.createTracker(
namespace: "appTracker",
network: networkConfig,
configurations: [trackerConfig, sessionConfig]
);
Was this page helpful?