This short tutorial will guide you through the basics of our API for C++ applications. The examples are made using Visual Studio 2010, but it should work well with previous versions of Visual Studio IDE.
Don’t forget to check the Complete DeskMetrics Analytics C++ API reference.
Are you ready?
This first step is very basic stuff. As any other dependency, you need to download the DeskMetrics Analytics package 32-bit or 64-bit, add the files DeskMetrics.h and DeskMetrics.cpp under Integration Units/CPP/ in your project. Then, you need to put the DeskMetrics.dll file into your PATH (usually, developers place this dll inside their C:\windows\system32 folder or at the same directory as the application executable).
After that, you need to add three lines of code inside your application in order to add very basic tracking:
#include "DeskMetrics.h"
int CDeskMetricsCPlusPlusDlg::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
DeskMetricsStart(L"YOUR APPLICATION ID", L"1.0");
if (CDialogEx::OnCreate(lpCreateStruct) == -1)
return -1;
return 0;
}
void CDeskMetricsCPlusPlusDlg::OnClose()
{
ShowWindow(SW_HIDE);
DeskMetricsStop();
CDialogEx::OnClose();
}
Calling the methods (DeskMetricsStart and DeskMetricsStop) is mandatory. The DeskMetricsStart method is responsible for gathering the machine information (like OS, plugins and VMs, hardware, etc) and the DeskMetricsStop method will send the gathered data to DeskMetrics Analytics.
Warning
your app won’t work if you don’t call these two methods in order in your application
You need the app id for the Start method. This ID identifies your application on DeskMetrics Analytics. Go to http://analytics.deskmetrics.com/ and you’ll see something like this:
You can find this on DeskMetrics Analytics page (http://analytics.deskmetrics.com/)
Those two methods are more useful than you might think. Try to run your application and then open its dashboard at http://analytics.deskmetrics.com/ and see what happens (Note: you’ll need to start and stop your application before you check the dashboard).
After you run and successfully close your application, you’ll be able to see the data on your Analytics page:
Mission accomplished, your first integration was done! You can see this data on your application’s Dashboard
Until now we’ve only added some very basic app tracking. You can track more sophisticated user information, such as event tracking. For example, you can add a button to your application and track when it is clicked like shown below:
#include "DeskMetrics.h"
int CDeskMetricsCPlusPlusDlg::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
DeskMetricsStart(L"YOUR APPLICATION ID", L"1.0");
if (CDialogEx::OnCreate(lpCreateStruct) == -1)
return -1;
return 0;
}
void CDeskMetricsCPlusPlusDlg::OnClose()
{
ShowWindow(SW_HIDE);
DeskMetricsStop();
CDialogEx::OnClose();
}
void CButton1::OnClick()
{
DeskMetricsTrackEvent(L"EventCategory", L"EventName");
}
By now, you already have some knowledge on the DeskMetrics Analytics platform. If you want to know more, we recommend reading the the complete DeskMetrics Analytics API reference in order to use all features DeskMetrics Analytics provide.