Dymatrix Flutter plugin

A Flutter plugin for the Dymatrix SDK.

Initialize the plugin

Initialize the plugin at application startup to create a new session.

Dymatrix.instance.init(
    clientKey: "xxxxx",
);

The plugin offers the following configuration options:

  • clientKey: Your client key provided by Dymatrix. Please contact your Dymatrix ecommerce consultant.
  • defaultPrivacySettingsNewUser: PrivacySettings used for new sessions without explicitly set PrivacySettings.
  • isSecureTransmit: Use HTTPS
  • customHostName: Value saved as Hostname in Dymatrix Analytics. If not otherwise stated, the hostname is: “Android/” + app name.
  • batchAutoTransmitTimeout: Optional timeout in seconds that is used when requests are first collected and then submitted as batch.
  • samplingRate: If set to a value n > 1 only each n-th user will be tracked.

We will automatically create a new session if the duration between page view events is longer than 30 minutes. You can start a new session manually by calling Dymatrix.instance.startNextSession().

Create and send a tracking event

Create a PageViewEvent object:

final event = PageViewEvent();

Add properties to the object:

event.content = 'test';

Add PageViewEvent to the session:

Dymatrix.instance.addPageView(event);

The session now contains PageViewEvent data.

Depending on the settings, the data will be transferred immediatly or after a timeout to the Dymatrix server. If you have set a batchAutoTransmitTimeout > 0, the data will be transmitted after the specified timeout. However, you can always force an immediate data submission using Dymatrix.instance.submitBatch().

You can use the WidgetsBindingObserver to submit the data that was collected for the current session when the application enters the paused state.

@override
void didChangeAppLifecycleState(AppLifecycleState state) {
    if (state == AppLifecycleState.paused) {
        Dymatrix.instance.submitBatch();
    }
}

Frequent data transmissions can drain a mobile device’s battery. To improve energy efficiency, consider collecting PageViewEvent data and sending it in batches rather than separately.

Change the PrivacySettings

You can change the PrivacySettings of the currently active session by calling

Dymatrix.instance.setPrivacySettings(newPrivacySettings);

The settings will be applied immediately and persisted for later use.

There are 4 predefined PrivacySettings:

  • anonym : Anonymized data is collected and transmitted.
  • cache : Data is collected but not transmitted until different privacy settings have been selected.
  • doNotTrack : Tracking is disabled.
  • full : Data is collected and transmitted.

Tracking in WebViews

Tracking of apps is done using the Dymatrix Flutter plugin or the Android and iOS SDKs, whereas HTML pages are tracked using the Dymatrix tracking library for Web.

If you include BOTH at the same time, the report will count 2 visitors instead of 1. This is because the SessionId and VisitorId do not match.

If you want to add tracking inside WebView widgets of your app you can use the JavaScript channel so send messages from the website to your app. Your app can then use the Dymatrix Flutter plugin to send the tracking events. The example app shows how to implement this.

Libraries

dymatrix_flutter