Android : Creating tracker.xml under res/xml

on Wednesday, September 3, 2014


I am working with Google Analytics for android app. By following this guide , I could't create xml file (global_tracker.xml like) under res/xml which contain resource tag . I can create the xml file under res/values folder. Then I copied from values paste it into xml folder.


After doing this I launch my app. In the Google analytics reporting page shows "There is no data for this view" in Screen session.


Below is my code to send data to Google analytics



Tracker t = ((MyApplication) this.getApplication()).getTracker(
TrackerName.APP_TRACKER);

// Set screen name.
// Where path is a String representing the screen name.
t.setScreenName("com.xxx.yyy.SplashScreen");

// Send a screen view.
t.send(new HitBuilders.AppViewBuilder().build());


In my Application class



public class RaagaApplication extends Application {

/**
* Enum used to identify the tracker that needs to be used for tracking.
*
* A single tracker is usually enough for most purposes. In case you do need multiple trackers,
* storing them all in Application object helps ensure that they are created only once per
* application instance.
*/
public enum TrackerName {
APP_TRACKER, // Tracker used only in this app.
GLOBAL_TRACKER, // Tracker used by all the apps from a company. eg: roll-up tracking.
ECOMMERCE_TRACKER, // Tracker used by all ecommerce transactions from a company.
}

HashMap<TrackerName, Tracker> mTrackers = new HashMap<TrackerName, Tracker>();
@Override
public void onCreate() {
// TODO Auto-generated method stub
super.onCreate();
}

synchronized Tracker getTracker(TrackerName trackerId) {
if (!mTrackers.containsKey(trackerId)) {

GoogleAnalytics analytics = GoogleAnalytics.getInstance(this);
Tracker t = (trackerId == TrackerName.APP_TRACKER) ? analytics.newTracker("UA-xxxxxxxx-1")
: (trackerId == TrackerName.GLOBAL_TRACKER) ? analytics.newTracker("UA-xxxxxxxx-1")
: analytics.newTracker("UA-xxxxxxxx-1");
mTrackers.put(trackerId, t);

}
return mTrackers.get(trackerId);
}

}


Can any one provide the details for the below queries ?



  1. How can I differentiate the PROPERTY-ID and TRACKER-ID ?

  2. How to configure the xml file under res/xml folder ?

  3. How to set the screen name and how to track in reporting page ?


1 comments:

Unknown said...

HI you have a good blog i like your blog as it have all the good information. for more
information Click on women Kurta

Post a Comment