Track an Event from Code

Oct 3, 2011 at 5:22 PM

Hey guys,

According to docs App.xaml updated with service and google analytics provider:

        <mwa:WebAnalyticsService >
                <ga:GoogleAnalytics WebPropertyId="UA-xxxx" Category="myApplication" />

In my code behind I  have:

        public Action<AnalyticsEvent> Log { getset; }
public void LogSomething(){ var ae = new AnalyticsEvent() { 
ActionValue = "RighBtnDown", 
Category = "CustomerRelationDashboardShell", 
Name = "RightBtnDownEvent", 
ObjectType = GetType().Name }; 
Property Log is initialized (it is Prism application) and application is working without exceptions/warnings.
But nothing is send to Google -  I see it via Fiddler. Fiddler meanwhile shows loading and loaded event (from applicationLifetimeObject) at startup.
Any idea why tracking from code doesn't work?
Oct 6, 2011 at 5:49 PM

I suspect that the problem is the properties you are setting on your AnalyticsEvent aren't those that are readily recognised by Google Analytics.

In my code I've been doing this simple translation of Analytics Event properties to Google Analytics syntax.


 Category category

Name action

ObjectName label

Value value


Therefore my Log calls usually look like so:

            Log(new AnalyticsEvent() {
                Category = MY_CATEGORY,
                ObjectName = A_LABEL,
                Name = AN_ACTION,
                Value = INTEGER_VALUE

Hope that helps!

Oct 6, 2011 at 6:00 PM

ok, added more properties into AnalyticsEvent class

   var ae = new AnalyticsEvent()
                Category = "xx",
                ObjectName = "yy",
                ActionValue = "RighBtnDown",
                Name = "RightBtnDownEvent on Shell",
                ObjectType = GetType().Name,
Same result - nothing is sent to google - Log(ae) is just silently finishes its work without any exception/message. 
Jan 5, 2016 at 7:09 AM