TCustomEventContext

From RAD Studio Code Examples
Jump to: navigation, search

Description

This FireMonkey code snippet shows how to track custom data by using custom events. In this example there is a custom event to capture the application user's local timezone and the UTC offset.

The UTC offset is the difference in hours and minutes from Coordinated Universal Time (UTC) for a particular place and date.

The Onclick event handler for the TriggerEventButton button sends information to appanalytics.embarcadero.com with the local time zone name and UTC offset value.

Code

Delphi code:

uses System.Analytics, System.Analytics.AppAnalytics, System.DateUtils;

procedure TForm1.EnableButtonClick(Sender: TObject);
begin
  AppAnalytics1.Enabled := True;
end;

procedure TForm1.TriggerEventButtonClick(Sender: TObject);
var
  Context: TCustomEventContext;
begin
  if Application.TrackActivity then
  begin
    Context := TCustomEventContext.Create('Customer_Timezone', 'Recorded Locale with UTC Offset', TTimeZone.Local.DisplayName,
      TTimeZone.Local.UtcOffset.Hours);
    Application.AnalyticsManager.RecordActivity(TAppActivity.Custom, TriggerEventbutton, Context);
  end;
end;

end.

C++ code:

// Include the libraries in <project.h> 

#include <System.DateUtils.hpp>
#include <System.Analytics.AppAnalytics.hpp>

void __fastcall TForm1::EnableButtonClick(TObject *Sender)
{
     AppAnalytics1->Enabled = True;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::TriggerEventButtonClick(TObject *Sender)
{
     TCustomEventContext *Context;

     if (Application->TrackActivity()) 
     {
          Context = new TCustomEventContext("Customer_Timezone", "Recorded Locale with UTC Offset", TTimeZone::Local->DisplayName, TTimeZone::Local->UtcOffset.Hours );
          Application->AnalyticsManager->RecordActivity(TAppActivity::Custom, TriggerEventButton, Context);
     }
}

AppAnalytics Custom Events.png

Uses

See Also