Skip to content
Damien Guard edited this page Apr 16, 2014 · 6 revisions

AutoMeasurement is a start but you'll certainly want to go further.

To allow users to opt in/out

You can either call AutoMeasurement.SetOptOut (only required if the user changes their choice as the value is persisted and restored for you) or there is a bindable class called AnalyticsUserOptions that can be bound to that automatically takes care of opting in and out. See the OptionsFlyout in the Windows 8 sample application for an example of usage.

To give a page a different name in analytics

The default name for a page is the class name of the page with "Page" removed from the end. e.g. "TopNewsPage" would be tracked as "TopNews".

For a screen name that doesn't change based on data consider adding the AnalyticsScreenName attribute to the page class. e.g.

[AnalyticsScreenName("Top news")]
class TopNewsPage {

For screen names that change depending on the data the screen is displaying add ITrackOwnView to the Page class. This empty marker interface does not require you do anything but signals to AutoMeasurement that you will track the screen view yourself. To do that you would add a line of code to the LoadState method of your page once the data has been loaded, e.g.

AutoMeasurement.Client.TrackAppView(item.Title);

For additional user events

If you want to track when the video "Today's News" is played back:

AutoMeasurement.Client.TrackEvent("Play", "Video", "Today's News");

There are two additional fields available for events:

  • Value - a numeric integer that is averaged and often used for timing
  • nonInteraction - setting this to true prevents the event from being used in bounce calculations

For timing

If you want to track how long something takes:

var timedActivity = new AutoTimedEventActivity("Loading", "Pictures");
// do something that takes time
AutoMeasurement.Client.Track(timedActivity);
```

## For sample rates

Sample rates allow you to reduce the amount of data going in to Google Analytics by randomly selecting a certain percentage of installations to be captured.

While this would be a useful feature it is **not recommended at this time** as there is no facility on the analytics dashboard to automatically adjust absolute numbers to compensate for this. Additionally should you change the sample rate you'd need to bump the app version number and break the figures down by app version to compensate for the app version numbers on a case-by-case basis.

Note that these are not limitations of CSharpAnalytics but limitations of Google Analytics.