Integrating the Tapstream PhoneGap SDK

From your main project directory, run:

phonegap plugin add tapstream-sdk-phonegap

This will download the Tapstream plugin and add it to your project. (Note that only iOS and Android PhoneGap projects are supported.)

Importing and initializing the SDK

Initialize Tapstream from your onDeviceReady: function like this:

tapstream.create('TAPSTREAM_ACCOUNT_NAME', 'TAPSTREAM_SDK_SECRET', {});

For Android projects, it is mandatory that you include the Google Play Services SDK.

Firing extra events

By default, Tapstream fires an event whenever a user runs the app. You can define further events for recording key actions in your app by using the syntax below:

// Regular event:
tapstream.fireEvent('test-event');

// One-time-only event:
tapstream.fireEvent('install', true);

// Regular event with custom params:
tapstream.fireEvent('test-event', false, {
    'my-custom-param': 3,
});

// One-time-only event with custom params:
tapstream.fireEvent('install', true, {
    'my-custom-param': 'hello world',
});

Global custom event parameters

You may find that you have some data that needs to be attached to every single event sent by the Tapstream SDK, including your Install and Open events.. Instead of writing the code to attach this data in each place that you send an event, add these data values to the global event parameters member of the config object. The parameters in this dictionary will automatically be attached to every event, including the automatic events fired by the SDK.

tapstream.create('TAPSTREAM_ACCOUNT_NAME', 'TAPSTREAM_SDK_SECRET', {
    custom_parameters: {
      some_key: "value"
   }
});

Changing the default behavior of the Tapstream SDK

Note: Changing this behavior is not usually required.

To change the default Tapstream config, provide config overrides like this:

tapstream.create('TAPSTREAM_ACCOUNT_NAME', 'TAPSTREAM_SDK_SECRET', {
    idfa: '<IDFA goes here>',
    collectDeviceId: true,
    collectWifiMac: false,
    secureUdid: '<SecureUDID goes here>',
    installEventName: 'custom-install-event-name',
    openEventName: 'custom-open-event-name',
});

Consult the platform-specific SDK documentation to see what config variables are available. Don't use accessor methods; instead, just set the variables directly, using camel-case capitalization

Preventing conflicts with Tapstream's JavaScript

If you're using your website inside of PhoneGap, and your website loads Tapstream's JavaScript, you need to modify your Tapstream JavaScript before proceeding.

First, add the following JavaScript snippet in PhoneGap so that it fires before onload:

window.__ts_suppress = true;

Then, modify your site's Tapstream JavaScript from this:

<script type="text/javascript">

var _tsq = _tsq || [];
_tsq.push(["setAccountName", "your_tapstream_account_name"]);
_tsq.push(["fireHit", "javascript_tracker", []]);

(function() {
    function z(){
        var s = document.createElement("script");
        s.type = "text/javascript";
...

to this:

<script type="text/javascript">

var _tsq = _tsq || [];
_tsq.push(["setAccountName", "your_tapstream_account_name"]);
_tsq.push(["fireHit", "javascript_tracker", []]);

(function() {
    function z(){
        // Return if the PhoneGap-only window variable is set
        if(window.__ts_suppress) return;
        var s = document.createElement("script");
        s.type = "text/javascript";
...

This will prevent Tapstreams JavaScript from firing hits from within your app.