You can currently use Application Insights to find out how people use your Windows 8.1 Store Apps & Managed Windows Phone 8.0 Apps. We’ve been asked about Phone 8.0 Direct3D C++ Apps as well, which the NuGet Package currently does not support. Here is a workaround that can enable you to use Application Insights for these apps.
Download the NuGet Package
Download the “Application Insights Telemetry SDK for Windows Phone Apps” NuGet package which contains the reference files we will use for our Direct3D C++ App. Once the package is downloaded, unzip and copy the “/build/wp80” folder to the solution directory or anywhere you want to keep the reference files. Open the “wp80” folder and rename “x86” to “Win32”. Here is what you will eventually get:
Right click your Windows Phone 8.0 Direct3D C++ App project, select Add, Reference, Add New Reference, Browse and select Microsoft.ApplicationInsights.Telemetry.WindowsStoreInternal.winmd from either the “Arm” or the “Win32” folder.
At this stage you will be able to use the Application Insights APIs for one specific platform (ARM or Win32). But you might want to switch the target platform between developing, testing, deploying, and packaging. You can ensure that the correct platform specific reference file gets picked up automatically:
- Right click the project in Solution Explorer and select Unload Project.
- Right click the project again and select Edit yourProject.vcxproj.
- In the .vcxproj file, find the “Microsoft.ApplicationInsights.Telemetry.WindowsStoreInternal” reference.
- In that reference block, edit the “HintPath” by replacing the name of the platform folder (e.g. Arm or Win32) with “$(Platform)”.
- Save the file and reload the project by right clicking on the project name in Solution Explorer.
For example, in my case, I have the following reference added:
And I will edit that to get this:
Now the correct reference will be picked up automatically, based on the target platform.
Get your Application Insights component ID
The next step is to provide an ID to the SDK that ensures that your data appears under your application component name in Application Insights.
- Sign in to your visualstudio.com account and go to Application Insights.
- Choose Add Application and then “click here” in Step 1.
- Choose Windows Phone 8 App Type and click to show further instructions.
- Ignore most of the instructions! You just want to get the component ID. Give a name to your application and choose “Create” (this is the application component in which you will see the usage reports once the data starts flowing).
- Copy the component ID from the code snippet.
Initialize the code with your component ID
Let’s come back to the project code to continue.
- Find your app’s Initialize() method in yourProjectName.cpp.
- Insert this at the top of the file:
using namespace Microsoft::ApplicationInsights::Telemetry::WindowsStoreInternal;
- At the end of the “Initialize” method, insert:
- Replace the <ApplicationInsightsId> with the component ID you copied from Application Insights Portal.
- Build and run the app on either Emulator or Device.
Get basic data
To see data in Application Insights:
- Run the app
- Terminate it using Back Key
- Re-launch the app
- Wait for 15-30 minutes, and then look for data in Application Insights under USAGE, with your application component selected. If you see a configuration page, you can “click to dismiss” the page.
Data is saved in a file in Isolated Storage when the app suspends or terminates, and is only sent to Application Insights when the app launches or resumes.
At this stage, the basic telemetry data will be collected – for example: OS Name, Application Version, Device Language, Network Type, etc. This will result in a variety of (insightful!) user and environment reports which you can browse through on the portal.
To get a sense of what the SDK is doing, check the Debug Messages in Output Window. You’ll see what telemetry is collected and sent to the collection server.
Get more data
To log additional data, use the following functions from the SDK for custom telemetry:
- Point Events: ClientAnalyticsChannel::Default->LogEvent
- Timed Events: ClientAnalyticsChannel::Default->LogTimedEvent
- Page Views: ClientAnalyticsChannel::Default->LogPageView
MSDN has details for similar methods in C# apps.
You’ll need the using statement in any file where you use those methods.
With this workaround, I hope you will be able to use Application Insights for your Windows Phone 8.0 Direct3D C++ Apps and start getting meaningful insights into your app’s usage. Please note that this is still a workaround and not a fully supported scenario. For questions and/or feedback, please visit the Application Insights Forum and for feature requests check out our User Voice!