TCustomEventContext (Object Pascal)

From Appmethod Code Examples
Jump to: navigation, search

Description

This example shows how to create custom events for tracking on FireMonkey.

The Onclick event handler for the TriggerEventButton button sends information to the server with the local time zone name and UTC offset value. 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 also send information with the OS name and build in case it exists.

Finally, the Onclick event handler for the Button1 button sends a '1' each time the user clicks the button. The Total Value column from the server sums up the total clicks.

Code

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

procedure TForm1.Button1Click(Sender: TObject);
var
  Context: TCustomEventContext;
begin
  Context := TCustomEventContext.Create('Button1', 'Recorded', 'Click', 1);
  Application.AnalyticsManager.RecordActivity(TAppActivity.Custom,
    Button1, Context);
end;

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

procedure TForm1.TriggerEventButtonClick(Sender: TObject);
var
  Context: TCustomEventContext;
  Context2: TCustomEventContext;
begin
  if Application.TrackActivity then
  begin
    Context := TCustomEventContext.Create('UserTimeZone', 'Recorded',
      TTimeZone.Local.DisplayName, TTimeZone.Local.UtcOffset.Hours);
    Context2 := TCustomEventContext.Create('OS Information', 'Recorded',
      TOSVersion.Name, TOSVersion.Build);
    Application.AnalyticsManager.RecordActivity(TAppActivity.Custom,
      TriggerEventButton, Context);
    Application.AnalyticsManager.RecordActivity(TAppActivity.Custom,
      TriggerEventButton, Context2);

  end;
end;

Uses