Skip to content

ebu/peach-collector-android

Repository files navigation

About

The Peach Collector module provides simple functionalities to facilitate the collect of events. PeachCollector helps you by managing a queue of events serialized until they are successfully published.

Compatibility

The library is suitable for applications running on Android API 16 and above. The framework is built using the build tools version 29.0.2

Setup

1. Provide the gradle dependency

Add it in your root build.gradle at the end of repositories:

allprojects {
  repositories {
    ...
    maven { url "https://jitpack.io" }
  }
}

Add the dependency:

dependencies {
  implementation 'com.github.ebu:peach-collector-android:1.0.0'
}

2. Initialize the collector

In your main activity, provide the application to the PeachCollector init function

PeachCollector.init(getApplication());

3. Add a publisher

You need to add a Publisher to start sending the queued events. You can either provide a SiteKey or set a URL address in order to configure the publisher.

Publisher publisher = new Publisher("zzebu00000000017");
PeachCollector.addPublisher(publisher, "My Publisher");

Configuring the collector

  • A user ID can be defined using the userID PeachCollector property.
  • A device ID can be defined using the setUserID function in PeachCollector. If set before initialization, PeachCollector will not try to retrieve an Advertising ID.
  • If userIDs are generated automatically for anonymous user. You can use the setUserIsLoggedIn() function to define if the user is logged in or not
  • For debugging purpose, a isUnitTesting flag is available. If true, notifications will be sent by the collector (see PEACH_LOG_NOTIFICATION constants)
  • The collector retrieves the Advertising ID to set as the device ID in order to track users that do not have user IDs. People can choose to limit tracking on their devices and the Advertising ID will not be available anymore. In this case, if there is no userID defined, no events will be recorder or sent. Unless you set the shouldCollectAnonymousEvents flag to true. Default is false.
  • Optionally, you can define an implementationVersion (that will be added to the request's payload).
  • inactivityInterval is the minimum duration (in milliseconds) of inactivity that will cause the sessionStartTimestamp to be reset when app becomes active (default is 1800000 milliseconds, half an hour)
  • maximumStorageDays is the maximum number of days an event should be kept in the queue (if it could not be sent).
  • maximumStoredEvents is the maximum number of events that should be kept in the queue. maximumStorageDays and maximumStoredEvents should be set before the initialisation of the framework as it will be used to clean the queue during the initialisation.
  • An appID can be defined if you don't want to use the default value (which is the bundle ID of the app).
PeachCollector.isUnitTesting = true;
PeachCollector.setDeviceID(UUID.randomUUID().toString());
PeachCollector.shouldCollectAnonymousEvents = true;
PeachCollector.userID = "123e4567-e89b-12d3-a456-426655440000";
PeachCollector.implementationVersion = "1";
PeachCollector.inactivityInterval = 3600000;
PeachCollector.maximumStorageDays = 5;
PeachCollector.maximumStoredEvents = 1000;
PeachCollector.appID = "my.test.app";

Configuring a Publisher

A publisher needs to be initialized with a SiteKey or a full URL address as seen previously. But it has 4 others properties that are worth mentioning :

interval: The interval in seconds at which events are sent to the server (interval starts after the first event is queued). Default is 20 seconds.

maxEventsPerBatch: Number of events queued that triggers the publishing process even if the desired interval hasn't been reached. Default is 20 events.

maxEventsPerBatchAfterOfflineSession: Maximum number of events that can be sent in a single batch. Especially useful after a long offline session. Default is 1000 events.

gotBackPolicy: How the publisher should behave after an offline period. Available options are SendAll (sends requests with maxEventsPerBatchAfterOfflineSession continuously), SendBatchesRandomly (separates requests by a random delay between 0 and 60 seconds).

publisher.serviceURL = "http://newEndPoint.com";
publisher.interval = 30;  
publisher.maxEventsPerBatch = 50;
publisher.maxEventsPerBatchAfterOfflineSession = 500;

Adding custom data to a Publisher's client information

Everytime events are sent to the defined SiteKey or server, the payload (containing the JSON description of the events) has a single description of the client used. You can add any custom fields to this client description and it will be sent in every request.

publisher.addClientField("country", "Germany");
publisher.addClientField("isGeolocalized", true);

Setting up a remote configuration

PeachCollector allows you to set up a remote configuration URL. Remote configurations are simple JSON files with different fields to configure the publisher. For that, you need to provide the URL at the initialisation stage of the publisher.

Publisher publisher = new Publisher("zzebu00000000017", "https://peach-bucket.ebu.io/zzebu/config-test.json");
PeachCollector.addPublisher(publisher, "MyRemoteConfiguredPublisher");

In this remote configuration, you can for example define the interval (at which events are sent), the batch size (number of events per request) or the type of events that should be sent by the publisher.

Flushing and Cleaning

Flush is called when the application is about to go to background, or if a special type of event is sent while in background (events that will potentially push the application into an inactive state). It will try to send all the queued events (even if the maximum number of events hasn't been reached)

Clean will simply remove all current queued events. It is never called in the life cycle of the framework.

Flush and Clean can be called manually.

Recording an Event

// page view event

Event.sendPageView("page00"+i, null, "reco00");


// recommendation displayed event

EventContextComponent carouselComponent = new EventContextComponent();  
carouselComponent.type = "Carousel";  
carouselComponent.name = "recoCarousel";  
carouselComponent.version = "1.0";  

ArrayList<String> items = new ArrayList<>();  
items.add("media00");  
items.add("media01");  
items.add("media02");  
items.add("media03");  

Event.sendRecommendationDisplayed("reco00", items , null, null, carouselComponent);

Setting up a player tracker

To track a player automatically, you just need to provide the ExoPlayer instance and information about the item that is being played. You can provide information about the item or leave empty. The tracker will only update (or create if not provided) the props part of the events with data from the player You can start and stop tracking an item manually.

PeachPlayerTracker.setPlayer(exoPlayer);
PeachPlayerTracker.trackMedia("video0001", null, null, null);
PeachPlayerTracker.clearCurrentItem(); 

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages