Events from iOS Apps
See the Overview for details about setting up the Datacoral Collect Events Slice.
Step 1: Get the tracker from Datacoral instrumentation library
Following command will download the tracker
You should have following directory:
Step 2: Copy the tracker into your project (MyObjcApp)
You only need to copy the tracker's ios-tracker/package/Snowplow/
sub-folder into your XCode project's folder. The command will look something like this.
Replace MyObjcApp with the name of your own app, and tweak the source code sub-folder accordingly.
Next, drag and drop the sub-folder MyObjcApp/MyObjcApp/Snowplow
into your XCode project's workspace.
Make sure that the suggested options for adding Snowplow are set Create groups, then click Finish.
Add the FMDB dependency
The tracker is dependent on FMDB version 2.3, an Objective-C wrapper around SQLite.
As before, git clone the dependency and copy the source into your XCode project's folder:
As before, drag and drop the sub-folder MyObjcApp/MyObjcApp/fmdb
into your XCode project's workspace, making sure to Create groups.
Finally, you will need to edit Snowplow/SPEmitter.m
and Snowplow/SPEventStore.m
in X-Code and change:
to
Add the Reachability dependency
For iOS only, the tracker is dependent on Reachability version 3.2, a drop in replacement for Apple's Reachability class.
As before, git clone the dependency and copy the source into your XCode project's folder:
Now add the Reachability.{h,m} files to your project by:
- Right-clicking on your MyObjcApp folder in XCode
- Selecting Add Files to "MyObjcApp"...
- Selecting both Reachability files and adding them
Once you have added the .h/m files to the project:
Step 3: Import all SystemConfiguration frameworks
- Go to Projects->TARGETS->Build Phases->Link Binary With Libraries
- Press the plus in the lower left of the list
- Add SystemConfiguration.framework
Import all required frameworks
The tracker also depends on various frameworks:
Go to Target > General tab > Linked Frameworks and Libraries section and add:
- All of the frameworks for your target platform, as returned by the grep above
- libsqlite3.dylib
Building
Now Build your project and you should see Build Succeeded. If you get a build error, check that you added Snowplow and fmdb as Groups, not just as Folders.
You are now ready to proceed to instrumenting your app. Just remember to use quotation marks not angle brackets, and the Snowplow sub-folder as necessary when importing the tracker:
Step 4: Creating a tracker
To instantiate a tracker in your code simply instantiate the SPTracker class with the following builder pattern after substituting the appropriate environment parameters.
URL_ENDPOINT : The URL of your Datacoral Events API gateway. Ex. events.dccustomer.datacoral.io
API_KEY : The Datacoral API key to authorize the events invocations. Ex. 1js9q5Gqmk2VDv2omx2WI3yUGV0K7b464fWUJXDX
ENVIRONMENT : Set the environment as dev
or prod
, based on the emitter of the events
NAMESPACE : The name of this Tracker instance to include with events sent to the collector. The namespace argument attached to every event fired by the new tracker. This allows you to later identify which tracker fired which event if you have multiple trackers running. Ex. landing_pages
APP_ID : Name of application to include with events sent to the collector. The application ID is used to distinguish different applications that are being tracked by the same Snowplow stack. Ex. "finance" or "hr"
Please substitute appropriate values for URLEndpoint, APIKey, Environment and AppId.
Tracking specific events
Refer to https://github.com/snowplow/snowplow/wiki/iOS-Tracker#events
Reference
https://github.com/snowplow/snowplow/wiki/iOS-Tracker-Setup https://github.com/snowplow/snowplow/wiki/iOS-Tracker