etracker
Analytics Editions / Pricing Live-Demo
etracker
Optimiser Editions / Pricing Live-Demo
Pricing For Agencies Support

Implementation

  • You add the tracking framework to your application as follows: 1. Copy 'tracking-framework.aar' to your project's libs folder. and add a dependency to your 'build.gradle' file like this:
    repositories {
            flatDir {
                dirs 'libs'
            }
        }
    
        dependencies {
            compile(name:'etracker-app-control-XXXXX.XXXXXX', ext:'aar')
        }
    
    If any problems occur with like `com.android.builder.packaging.DuplicateFileException`, please add the following lines to your 'build.gradle'
    packagingOptions {
                exclude "/META-INF/LICENCE"
                exclude "/META-INF/LICENSE"
                exclude "/META-INF/LICENCE.txt"
                exclude "/META-INF/LICENSE.txt"
                exclude "/META-INF/NOTICE"
                exclude "/META-INF/NOTICE.txt"
                exclude "/LICENCE"
                exclude "/LICENCE.txt"
                exclude "/NOTICE"
                exclude "NOTICE.txt"
         }
    
    See also PackagingOptions To keep a reference to the 'com.etracker.tracking.Tracker' instance around, we recommend to create a custom android.app.Application subclass like this:
    import android.app.Application;
    public class TrackingApplication extends Application {
        private Tracker tracker;
        @Override
        public void onCreate() {
            super.onCreate();
            tracker = Tracker.getInstance(this);
            // Example for accountKey
            String accountKey ="XXXXXX";
            // Example for Api key (API key is optional)
            String apiKey = "d41d8cd98f"; 
            tracker.startTracker(accountKey, apiKey);
        }
        @Override
        public void onTerminate() {
            super.onTerminate();
            tracker.stopTracker();
        }
    }
    Note: To avoid any issues with Norton Antivirus or similar products that raise any data privacy concerns, we introduced a new way to initialize the startTracker(), that does not use the Android PackageManager to resolve the app name and app version. Thus the app name and app version is recommend to be provided by using one of the following method signatures.
    startTracker(String accountKey, String appName, String appVersion)
    startTracker(String accountKey, String sharedSecret, String appName, String appVersion)
    startTracker(String accountKey, String sharedSecret, int timeInterval, String appName, String appVersion)
    2. Within the created subclass provide the accountKey and, if you want to have the requests signed, the optional API key you got from etracker resp. registered with your account. By default, pending events are sent to the server once every minute. 3. Refer to the above subclass in your AndroidManifest.xml like this:
    <manifest xmlns:android="http://schemas.android.com/apk/res/android" ...>
        ... 
        <application android:label="@string/app_name" android:icon="@drawable/icon" android:name=".TrackingApplication">
        ... 
        </application>
        ... 
    </manifest>
    4. As the tracker needs to access the internet, you have to add the INTERNET permission to the AndroidManifest.xml:
    <manifest xmlns:android="http://schemas.android.com/apk/res/android" ...>
        ...
        <uses-permission android:name="android.permission.INTERNET" />
        ...
    </manifest>
    5. Access the 'global com.etracker.tracking.Tracker' instance in your classes like this:
    public class TestActivity extends Activity {
        private Tracker tracker;
        @Override
        public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ...
        tracker = Tracker.getInstance(this);
        }
    }
    6. Before using the tracking service, you should get the visitor's consent of getting tracked. You can do this by integrating a code snippet in your application like the example below. Via this code snippet the visitor is asked for his consent of getting tracked and the answer is stored by the tracking service. Because of the storage the question is asked only once.
    Note: Please notice that no events are tracked until the visitor's consent has been given.
    if (tracker.getUserConsent() == UserConsent.Unknown) {
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setMessage("Do you allow anonymous tracking?");
        builder.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialogInterface, int i) {
                tracker.setUserConsent(UserConsent.Granted);
            }
        });
        builder.setNegativeButton("No", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialogInterface, int i) {
                tracker.setUserConsent(UserConsent.Denied);
            }
        });
        builder.create().show();
    }
    • All events are documented in the JavaDoc that is delivered together with the library. The following events are available:
      EventDescription
      trackScreenViewScreen call.
      track OrderSending an InApp order.
      trackUserDefinedTracks a custom event.
      trackScreenView and trackOrder are convenience events that simplify the use of custom events. Visitor sessions are determined automatically: Actions in an app within a time interval of 30 minutes are assigned to one visitor session. To track a screen view event, call trackScreenView("screenName") like this:
      tracker.trackScreenView("myScreenView");
      To track a user defined event, call trackUserDefined() like this:
      tracker.trackUserDefined("categoryName", "actionName", "objectName", "42");
      If you want to make sure that all pending events are sent to the server now, you can call flush():
      tracker.flush();
      Data to be transmitted to the server are:
      • For every chunk transmitted to the backend: device model, system version, language code, and country code
      • For each tracked event: timestamp and the string you have chosen to describe the event you want to track.
      Like all other methods, this one runs asynchronously. So, if you try to send events just before terminating the application, there might not be enough time to send everything. In that case, events will be sent once the application and therefore the tracker is restarted.
    You add the tracking framework to your application as follows: 1. Copy 'ETRTracker.h' and the associated library 'libETRTracker.a' into your application's project folder. Make sure that your application links against that static library. 2. In your application delegate, import the header file:
    #import "ETRTracker.h"
    3. Initialize the tracking service in '-application:didFinishLaunchingWithOptions:', provide the accountKey and, if necessary, the optional shared secret (API key) you got from etracker resp. registered with your account. By default, pending events are sent to the server once every minute, but you can provide a different time interval. Just overwrite 'timeInterval:ETRDefaultTimeInterval' by your preferred value (in s):
    [[ETRTracker sharedTracker] startTrackerWithAccountKey:@"XXXXXX" sharedSecret:@"14a34554" timeInterval:ETRDefaultTimeInterval];
    4. Before using the tracking service, you must get user consent to comply with Apple's terms for application developers. To do this, integrate a code snippet like the following example in your application. By default, user consent is unknown. Due to the code snippet the user will be asked and the tracking service will store the user's answer. That way, the question is asked only once:
    Note: Please notice that no events are tracked until user consent has been given.
    - (void)askForUserConsent {
       if ([[ETRTracker sharedTracker] userConsent] == ETRUserConsentUnknown) {
          UIAlertView *alertView = [[UIAlertView alloc]
             initWithTitle:@""
             message:@"Do you allow anonymous tracking?"
             delegate:self
             cancelButtonTitle:@"No"
             otherButtonTitles:@"Yes", nil];
            [alertView show];
       }
    }
    - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
        ETRUserConsent userConsent = buttonIndex ? ETRUserConsentGranted : ETRUserConsentDenied;
        [[ETRTracker sharedTracker] setUserConsent:userConsent];
    }
    • All events are documented in the header file ETRTracker.h that is delivered together with the library. The following events are available:
      EventDescription
      trackScreenViewScreen call.
      trackOrderSending an InApp order.
      trackUserDefinedTracks a custom event.
      'trackScreenView' and 'trackOrder' are convenience events that simplify the use of custom events. Visitor sessions are determined automatically: Actions in an app within a time interval of 30 minutes are assigned to one visitor session. To track a screen view event, call -trackScreenView: like this:
      [[ETRTracker sharedTracker] trackScreenView:@"shopping card"];
      To track a user defined event call trackUserDefined like this:
      [[ETRTracker sharedTracker] trackUserDefined:@"category" action:@"action" object:@"object" value:[NSString stringWithFormat:@"%d", 42]];
      If you want to make sure that all pending events are sent to the server immediately, you can call -sendPendingEventsNow. The library will attempt to send all pending events up to twelve times with growing delays.
      [[ETRTracker sharedTracker] sendPendingEventsNow];
      To clean up, we recommend to stop the tracker in -applicationWillTerminate: like this:
      [[ETRTracker sharedTracker] stopTracker];
    To track views and visits within a hybrid app it is just necessary, like in regular HTML websites, to implement the regular tracking code which you can find within the settings of your etracker account.

Need help?
Our friendly, knowledgeable support engineers are here for you.