Tracking Custom Events with TAppAnalytics in Multi-Device Applications

Posted by on in Tools

Luis Navarro recently wrote a great post on using the new TAppAnalytics component in your VCL and FireMonkey applications to track application usage.

Today, I thought I would provide a quick FireMonkey code snippet that shows you how to track custom data. In this example, I am able to capture the application user's local timezone and the UTC offset.

When creating the Context Object, none of the three strings can be empty. The parameters are Category, Action, Text and Value.

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

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.

 AppAnalytics

We are doing a developer skill sprint on app analytics on May 19th. You can register for the webinar by going to http://embt.co/Sprints15.

To learn more about App Analytics with RAD Studio XE8, visit http://www.embarcadero.com/products/appanalytics 

Trial Banner



About
Gold User, Rank: 5, Points: 558
Senior Product Manager, RAD Studio

Comments

  • Sarina D
    Sarina D Thursday, 14 May 2015

    Hi Fred,
    That is the case for VCL, but FireMonkey handles tracking custom app analytics events differently.

    Regards,
    Sarina

  • Fred A5467
    Fred A5467 Thursday, 7 May 2015

    Why don't you just call TAppAnalytics.TrackEvent?

  • Please login first in order for you to submit comments
  • Page :
  • 1

Check out more tips and tricks in this development video: