Skip to content

visenze/flutter-tracking-sdk

Repository files navigation

visenze-tracking-sdk

Pub Platform License Null Safety

Table of Contents

Overview

Visenze Analytics is a key part of your analytics solutions, allowing you to track key events and view the resulting analytics and performance data.

The ViSenze Tracking SDK is an open source software for easy integration of ViSearch Tracking API with your flutter application. For source code and references, visit the GitHub repository.

Usage

Installing

Run this command

flutter pub add visenze_tracking_sdk

Importing

import 'package:visenze_tracking_sdk/visenze_tracker.dart';

Future<void> init() async {
  var tracker = await VisenzeTracker.create('MY_APP_KEY:MY_PLACEMENT_ID');
}

Setting user id

The uid (user identifier) drives features like a/b testing and personalization. By default, we generate an uid based on the user's browser/device information. However, for improved data synchronization with your internal records, you can set your own uid. By incorporating your own uid, you enhance data integration and alignment with your systems. This flexibility enables seamless tracking and analysis, maximizing the benefits of our platform within your existing infrastructure.

To set your own UID, use this code:

tracker.userId = 'MY_UID';

Getting tracking data

You also have the option to retrieve the automatically generated user id and session id. To obtain the user id and session id, you can use the following code:

String uid = tracker.userId;
String sid = tracker.sessionId;

Sending events

All events sent to Visenze Analytics server require the search query ID (the reqid) found in the search results response as part of the request parameter.

Some events (for e.g. product_click or product_view) can require additional parameter like pid (product id).

Single events

User action can be sent through an event handler. Register an event handler to the element in which the user will interact.

// send product click
tracker.sendEvent('product_click', {
  'queryId': '<search reqid>',
  'pid': '<your product id>', // necessary for product_click event
  'pos': 1, // product position in Search Results, start from 1
});

// send product impression
tracker.sendEvent('product_view', {
  'queryId': '<search reqid>',
  'pid': '<your product id>', // necessary for product_view event
  'pos': 1, // product position in Search Results, start from 1
});

// send Transaction event e.g order purchase of $300
tracker.sendEvent('transaction', {
  'queryId': "<search reqid>",
  'transId': "<your transaction ID>"
  'value': 300
});

// send Add to Cart Event
tracker.sendEvent('add_to_cart', {
  'queryId': '<search reqid>',
  'pid': '<your product id>',
  'pos': 1, // product position in Search Results, start from 1
});

// send custom event
tracker.sendEvent('favourite', {
  'queryId': '<search reqid>',
  'pid': 'custom event label',
  'cat': '<product category>'
});

// handle success or error
try {
  await tracker.sendEvent('product_view', {
    'queryId': '1234',
    'pid': 'Product Id',
    'pos': 1
  });
  onRequestSuccess() // handle success case
} catch (errResponse) {
  onRequestError(errResponse) // handle error case
}

Batch events

Batch actions can be sent through a batch event handler.

A common use case for this batch event method is to group up all transaction by sending it in a batch. This SDK will automatically generate a transId to group transactions as an order.

const transactions = [
  {'queryId': '1234', 'pid': 'Pid 1', 'value': 50},
  {'queryId': '1234', 'pid': 'Pid 2', 'value': 100}
];
tracker.sendEvents('transactions', transactions);

Event parameters

For the detailed list of event parameters, please refer to this doc.

Example

Example

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors 4

  •  
  •  
  •  
  •