analytics.xml configurations not being picked up

Jul 22, 2013 at 10:24 AM
Hi Tim,

I am trying to use this in Windows 8 metro app, but it simply does not read from analytics.xml and I keep getting the exception "One or more error occurred". When I changed the code a bit than the one mentioned in documentation it starts working, but I have to explicitly supply the tracker id, it does not read from the xml file. Does it read from analytics.xml or is it a known issue that it does not read from analytics.xml in case of Windows 8:

Code that does not work:

GoogleAnalytics.EasyTracker.GetTracker().SendEvent(eventName, "userclick", null, 0);

Code that works:

public class analyticswrapper
{
private static GoogleAnalytics.GoogleAnalytics gaInstance = GoogleAnalytics.GoogleAnalytics.Current;
private static GoogleAnalytics.Tracker gaTracker = gaInstance.GetTracker("U-XXX-Y"); // I supply the correct tracker id here
    public static void SendEvent(string eventName)
    {
        try
        {
           gaTracker.SendEvent(eventName, "userclick", null, 0);
        }
        catch (Exception ex)
        {
            _log.write("SendEvent: {0} ", ex.Message);
        }
    }
}

-Sharath
Coordinator
Jul 22, 2013 at 8:29 PM
Using EasyTracker is the recommended approach. Make sure analytics.xml is in your main project (not in a dependency project) and make sure Build Action is set to Content on the file. Lastly, make sure the schema is followed and that your GA ID is set correctly. If you still have trouble, feel free to send me the analytics.xml file and/or a repro project and I'll take a look.
Jul 23, 2013 at 7:25 AM
Thanks very much Tim. It works now.

-Sharath
Oct 11, 2013 at 1:12 PM
Hi Tim,

is it also possible to set all the properties like Tracking ID without having the analytics file?
Coordinator
Oct 17, 2013 at 4:06 PM
@huserben, you can set the config programmatically by calling something like this:
            GoogleAnalytics.EasyTracker.Current.Config = new GoogleAnalytics.EasyTrackerConfig()
            {
                TrackingId = "UA-39959863-1",
                AppName = "My app"
            };
Just be sure to call this anytime before you make your first call to GoogleAnalytics.EasyTracker.GetTracker() or it will try to use the xml file instead.
Oct 18, 2013 at 11:21 AM
Hi Tim,

yes thanks, I figured this out after a quick look into the code :-)
Problem was that I indeed called GoogleAnalytics.EasyTracker.GetTracker() before setting the config.

Also just as a hint, I use your SDK within a Phonegap/Cordova project as a plugin, where you have to call the gettracker method like this:
Deployment.Current.Dispatcher.BeginInvoke(() => tracker = EasyTracker.GetTracker());
Otherwise there will be some exceptions due to unauthorized access because I think it does not run in the UI-Thread.
This may help someone else who will use it in Cordova.

Anyway thanks for the nice SDK, works like a charm :-)
Apr 20, 2015 at 6:31 AM
Hi Tim ,

I am trying to create a class library using this sdk which i can use across all my apps.

It worked fine when i used it for my windows phone apps but it gives me an error when i refer it with my windows 8.1 apps .
The error is "Payload file Analytics.xml" does not exist.

I am setting the config programmatically like this
GoogleAnalytics.EasyTracker.Current.Config = new GoogleAnalytics.EasyTrackerConfig()
        {
            TrackingId = "UA-65549867-1",
            AppName = "My Test aPP"
        };
Is there any other way to make a library which i can use across all my apps?

Thanks & Regards
Nikhil