This short tutorial will guide you through the basics of our API for Delphi applications. The examples are made using Delphi 2009, but it should work well with previous versions of Delphi IDE.
Don’t forget to check the Complete DeskMetrics Analytics Delphi 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 file under Integration Units/Delphi/DeskMetrics.pas 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:
//the DeskMetrics library
uses DeskMetrics;
procedure TForm1.FormCreate(Sender: TObject);
begin
//initializes your application
DeskMetricsStart('YOUR APPLICATION ID', '1.0');
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Self.Visible := False;
//finalizes the application and send the collected data to DeskMetrics
DeskMetricsStop;
end;
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:
//the DeskMetrics library
uses DeskMetrics;
procedure TForm1.FormCreate(Sender: TObject);
begin
//initializes your application
DeskMetricsStart('YOUR APPLICATION ID', '1.0');
end;
procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Self.Visible := False;
//finalizes the application and send the collected data to DeskMetrics
DeskMetricsStop;
end;
procedure TForm2.Button1Click(Sender: TObject);
begin
//tracks a button click event
DeskMetricsTrackEvent('ButtonClick','Button1')
end;
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.