How do I integrate Advanced Analytics SDK in my Java application?

Requirements

To integrate Advanced Analytics in a Java application you can follow this article which explains Program.java from the Java sample on GitHub.

TipWe encourage you to use this sample as a starting point so you can understand how the SDK works, then to expand the logic and use your own methods according to your application's architecture.

The exported functions that leverage the SDK functionality are:

  • AA_Start(appID, appVersion) - Initializes the service using the appID and appVersion parameters. This method must be called before any other calls to the SDK.
  • AA_Stop() - After this function is called, any further calls to the SDK will not work.
  • AA_Enable(true|false) - Enables/disables data sending to the server.
  • AA_IsEnabled() - Returns true/false depending on whether data sending is enabled/disabled.

Step 1 - Load the SDK native DLL and the JNI library used to bridge the native function calls

System.load is used in the sample(in AdvancedAnalytics.java) to load the libraries, but you can use any other method.

System.load(path + "/../../sdk/x64/AdvancedAnalytics_x64.dll");
System.load(path + "/../../sdk/x64/AdvancedAnalyticsJavaBridge.dll");

Step 2 - Get the app id from your Advanced Installer project or from your Installer Analytics account.

App id

Step 3 - Set a couple variables to the app id and version.

They will be passed as parameters to initialize the service.

String appId = "012345678901234567890123";
String appVersion = "1.0.0";

Step 4 - Initialize the service using Start which calls AA_Start from the SDK.

AdvancedAnalytics.Start(appId, appVersion);

Step 5 - Get the user's consent to enable tracking of your app.

The following snippet uses Swing with a simple message box, but you can feel free to implement how the interaction, if any, should be carried out.

int dialogResult = JOptionPane.showConfirmDialog(null, "Do you enable tracking?");
if (dialogResult == JOptionPane.YES_OPTION)
  AdvancedAnalytics.Enable(true);

In the sample, a registry entry is used to store the user's choice and verify it every time the app starts. Instead of registry entries you can use a file, DB or whatever suits your app.

Data sending will be disabled by default until you call AA_Enable through Enable with true. Once you do, the SDK sets its own registry value to persist the setting.

NoteYou won't be able to see any data in the reports until you call AA_Enable through Enable with true.

Step 6 - Run the application.

RunApp();

Step 7 - When the app needs to close, stop the tracking service using Stop, which calls AA_Stop from the SDK.

AdvancedAnalytics.Stop();