package cc.softwarefactory.lokki.android.utilities;


import android.content.Context;

import com.google.android.gms.analytics.GoogleAnalytics;
import com.google.android.gms.analytics.HitBuilders;
import com.google.android.gms.analytics.Tracker;

import cc.softwarefactory.lokki.android.R;

public class AnalyticsUtils {
    private static Tracker tracker;

    public static void initAnalytics(Context context) {
        tracker = GoogleAnalytics.getInstance(context).newTracker(R.xml.analytics_global_tracker_config);
        tracker.set("&uid", Utils.getDeviceId());
    }

    public static void screenHit(String screenName) {
        tracker.setScreenName(screenName);
        tracker.send(new HitBuilders.ScreenViewBuilder().build());
    }


    public static void eventHit(String category, String action, String label, long value) {
        HitBuilders.EventBuilder eventBuilder = new HitBuilders.EventBuilder()
                .setCategory(category)
                .setAction(action);
        if (label != null) {
            eventBuilder = eventBuilder.setLabel(label);
        }
        if (value != -1) {
            eventBuilder = eventBuilder.setValue(value);
        }
        tracker.send(eventBuilder.build());
    }

    public static void eventHit(String category, String action, String label) {
        eventHit(category, action, label, -1);
    }

    public static void eventHit(String category, String action, long value) {
        eventHit(category, action, null, value);
    }

    public static void eventHit(String category, String action) {
        eventHit(category, action, null, -1);
    }

}

@@ -403,24 +403,272 @@
  context) %7B%0A
+        int globalTrackerConfigXmlId = context.getResources().getIdentifier(%22analytics_global_tracker_config%22, %22xml%22, context.getPackageName());%0A        if (globalTrackerConfigXmlId == 0) %7B%0A            tracker = null;%0A            return;%0A        %7D%0A
         trac
@@ -725,45 +725,32 @@
 ker(
-R.xml.analytics_
 global
-_t
+T
 racker
-_c
+C
 onfig
+XmlId
 );%0A 
@@ -855,24 +855,85 @@
 reenName) %7B%0A
+        if (tracker == null) %7B%0A            return;%0A        %7D%0A
         trac
@@ -1038,16 +1038,16 @@
     %7D%0A%0A%0A
-
     publ
@@ -1122,32 +1122,93 @@
 , long value) %7B%0A
+        if (tracker == null) %7B%0A            return;%0A        %7D%0A
         HitBuild

Create null tracker if global tracker config missing