Countly Documentation

Countly Resources

Here you'll find comprehensive guides to help you start working with Countly as quickly as possible.

Windows & Windows Phone

This document explains how to install Countly SDK for Windows Phone and Windows desktop applications.

Minimum Windows version

Countly Windows SDK supports following operating system versions:

Windows Phone 7.1
Windows Phone 8.0
Windows Phone 8.1 Silverlight
Windows Phone 8.1 Runtime
Windows 8.1
Windows 10
Windows 10 Mobile
.NET 3.5
.NET 4.0 Client Profile
.NET 4.5 and above
Xamarin (Android, iOS)

In order to set up Countly SDK in your Windows Store or Windows Phone app, follow these steps:

  1. In Solution Explorer open context menu on References - Manage NuGet Packages.
  2. Select nuget.org in Package source.
  3. Type Countly in search box.
  4. Select Countly Analytics from results list and click Install button.

Set up SDK for Windows Phone Silverlight project

Countly SDK requires ID_CAP_IDENTITY_DEVICE and ID_CAP_NETWORKING to be enabled. Open WMAppManifest.xml, click on Capabilities section and make them enabled.

Add using CountlySDK; in the App.xaml.cs usings section

Call Countly.StartSession("http://YOUR_SERVER", "YOUR_APP_KEY", this) in App.xaml.cs Application_Launching and Application_Activated events, which requires your App key and the URL of your Countly server

If you are using Countly Enterprise Edition trial servers, the URL should be https://try.count.ly, https://us-try.count.ly or https://asia-try.count.ly. Basically the domain you are accessing your dashboard from.

Call Countly.EndSession() in App.xaml.cs Application_Deactivated and Application_Closing events. If you are using Windows Phone 8.x make sure you use async/await statements, so app will not be closed before Countly receives end session event

...
	// Code to execute when the application is launching (eg, from Start)
	// This code will not execute when the application is reactivated
	private void Application_Launching(object sender, LaunchingEventArgs e)
	{
		Countly.StartSession("http://YOUR_SERVER", "YOUR_APP_KEY", this);
	}

	// Code to execute when the application is activated (brought to foreground)
	// This code will not execute when the application is first launched
	private void Application_Activated(object sender, ActivatedEventArgs e)
	{
		Countly.StartSession("http://YOUR_SERVER", "YOUR_APP_KEY", this);
	}

	// Code to execute when the application is deactivated (sent to background)
  // This code will not execute when the application is closing
	private async void Application_Deactivated(object sender, DeactivatedEventArgs e)
	{
		await Countly.EndSession();
	}

	// Code to execute when the application is closing (eg, user hit Back)
	// This code will not execute when the application is deactivated
	private async void Application_Closing(object sender, ClosingEventArgs e)
	{
		await Countly.EndSession();
	}
...

Note: Make sure you use App Key (found under Management -> Applications) and not API Key. Entering API Key will not work.

Set up SDK for Windows Store project

Countly SDK requires Internet (Client & Server) to be enabled. Open Package.appxmanifest, click on Capabilities section and make it enabled

Add using CountlySDK; in the App.xaml.cs usings section

You need to call await Countly.StartSession(ServerUrl, AppKey, this); each time when app is activated and await Countly.EndSession(); when app is deactivated.
Add Countly.StartSession(ServerUrl, AppKey, this); to OnLaunched, OnActivated and OnResuming events

OnLaunched event is already prepared for you by Visual Studio in App.xaml.cs file. Add initialization code before page navigation happens.

protected override void OnLaunched(LaunchActivatedEventArgs e)
{
  
...

	Countly.StartSession("http://YOUR_SERVER", "YOUR_APP_KEY", this);
  
  if (rootFrame.Content == null)
	{
		// Removes the turnstile navigation for startup.
		if (rootFrame.ContentTransitions != null)
		{
			this.transitions = new TransitionCollection();
			foreach (var c in rootFrame.ContentTransitions)
		{
			this.transitions.Add(c);
		}
	}
    
...
}

Add override method called OnActivated to App.xaml.cs file and call Countly.StartSession(ServerUrl, AppKey, this); inside

protected override void OnActivated(IActivatedEventArgs args)
{
	Countly.StartSession("http://YOUR_SERVER", "YOUR_APP_KEY", this);
}

Subscribe to application Resuming method in App constructor.

public App()
{
	this.InitializeComponent();
	this.Resuming += this.OnResuming;
	this.Suspending += this.OnSuspending;
}

private void OnResuming(object sender, object e)
{
	Countly.StartSession("http://YOUR_SERVER", "YOUR_APP_KEY", this);
}

Update OnSuspending method created by Visual Studio in App.xaml.cs file to handle Countly deactivation logic. Make sure you use async/await statements, so app will not be closed before Countly receives end session event

private async void OnSuspending(object sender, SuspendingEventArgs e)
{
	var deferral = e.SuspendingOperation.GetDeferral();

	await Countly.EndSession();

	deferral.Complete();
}

Note: Make sure you use App Key (found under Management -> Applications) and not API Key. Entering API Key will not work.

Make sure you also fill in YOUR_SERVER part, either with IP address or the name of the server you installed Countly on.

Set up SDK for .NET project

Add using CountlySDK; in the usings section

You need to call Countly.StartSession(ServerUrl, AppKey, AppVersion); in entry point of the app and Countly.EndSession(); before app is closed

Using custom events

In all the examples below we will be recording a purchase event. Here is a quick summary what information each usage will provide us.

Data passed should be in UTF-8

All data passed to Countly instance via SDK or API should be in UTF-8.

  • Usage 1: how many times purchase event occured.
  • Usage 2: how many times purchase event occured + the total amount of those purchases.
  • Usage 3: how many times purchase event occured + which countries and application versions those purchases were made from.
  • Usage 4: how many times purchase event occured + the total amount both of which are also available segmented into countries and application versions.

First, add using CountlySDK; in the usings section

1. Event key and count

   Countly.RecordEvent("purchase");

2. Event key, count and sum

   Countly.RecordEvent("purchase", 1);

3. Event key and count with segmentation(s)

   Countly.RecordEvent("purchase", 1, 0.99);

4. Event key, count and sum with segmentation(s)

   Segmentation segmentation = new Segmentation();
   segmentation.Add("country", "Germany");
   segmentation.Add("app_version", "1.0");
   Countly.RecordEvent("purchase", 1, segmentation);

Note: For record events from Background Agent (applies for Windows Phone & Windows Store apps), call Countly.StartBackgroundSession("http://YOUR_SERVER", "YOUR_APP_KEY") to init Countly instance

   protected override async void OnInvoke(ScheduledTask task)
   {
      Countly.StartBackgroundSession("http://YOUR_SERVER", "YOUR_APP_KEY");
      await Countly.RecordEvent("purchase");
      NotifyComplete();
   }

Note: use async/await in background agent. This allows to call NotifyComplete() only when record is processed

Setting up User Profiles

Availability

This feature is available with Enterprise Edition subscription.

You can save info about user tracking data is related to. Countly provides Countly.UserDetails object that exposes user-related properties

Each time you change property value, Countly syncs it with a server. If you set value as null, you will delete the property.

Countly.UserDetails.Name = "John"; // set name to John
Countly.UserDetails.Name = "null"; // remove name

You can provide custom properties for user using Custom object

Countly.UserDetails.Custom.Add("city", "london");

Additionally you can upload picture of the user to the server. Accepted picture formats are .png, .gif and .jpeg and picture will be resized to maximal 150x150 dimensions.

Countly.UserDetails.UploadUserPicture(picture_stream);

Note: dots (.) and dollar signs ($) in key names will be stripped out.

Setting up Crash Reports

Countly SDK has an ability to automatically collect crash reports which you can examine and resolve later on the server. This applies for Windows Phone & Windows Store apps, on other platforms you should subscribe to unhandled exceptions handler manually. Exception details and device properties will be sent on next app launch.

To log handled exceptions, which are not fatal, use Countly.RecordException; method. You can provide custom properties for crash providing key/value object to store for this crash report and server will segment values for you for the same crash.

Following command adds crash breadcrumb like log record to the log that will be send together with crash report Countly.AddBreadCrumb;

Using SDK sample

Windows Phone SDK also has an example application that you can download, compile and run on your app or Visual Studio, in order to test sending data to Countly server.

  1. Download Countly Windows Phone SDK

  2. Extract all files to any folder

  3. Open Countly.sln file with Visual Studio 2012 or higher version

  4. Now you have two projects in your solution: Countly (SDK library) and CountlySample (quickstarter project).

  5. Open App.xaml.cs and MainPage.xaml.cs and type ServerUrl and AppKey to prepared fields

  6. Right click to CountlySample project and click "Set as StartUp Project"

  7. You can run your application on a device or an emulator provided by Visual Studio Windows Phone development kit.

Enabling logging

In order to make sure that requests to Countly are sent correctly, you need to enable logging using following:

    Countly.IsLoggingEnabled = true;

You can turn it on and off in any place of your code.