GithubHelp home page GithubHelp logo

00mjk / qubit-sdk-android Goto Github PK

View Code? Open in Web Editor NEW

This project forked from qubitdigital/qubit-sdk-android

0.0 0.0 0.0 618 KB

Qubit Android SDK

License: Apache License 2.0

Java 84.01% Kotlin 15.99%

qubit-sdk-android's Introduction

Qubit Android SDK

Installation of the QubitSDK, to provide event tracking and lookup. To make use of this SDK, please contact your Qubit Customer Success representative.

Releases

VERSION UPDATES
1.4.1 Handle potential regression where /experiences endpoint does not return expected payload.
1.4.0 Production release for A/B testing & data collection.

Getting started

Dependency

In build.gradle of your Android application module (usually $projectRoot/app/build.gradle) add the following in the dependencies section:

dependencies   {
    compile  'com.qubit:qubit-sdk-android:1.4.1'
}

Initialization

Provide application context and tracking ID (log level is optional - see more: Logging) and call start method to initialize SDK. You might place this code in your Application file:

@Override
public void onCreate() {
    super.onCreate();

    QubitSDK.initialization()
        .inAppContext(this)
        .withTrackingId("YOUR_TRACKING_ID")
        .withLogLevel(QBLogLevel.DEBUG)
        .start();
}

Permissions

Qubit's Android SDK needs the following permissions to communicate with the server and to detect network connectivity (they are added in library manifest):

  <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
  <uses-permission android:name="android.permission.INTERNET" />

Note that you don't have to add these permissions to manifest of your application.

Send events

Sending events

QProtocol (QP) is Qubit’s industry standard, extensible data layer. To send a QP event, call the sendEvent method taking QBEvent object as an argument, as per the following example. The following example emits a standard ecView event, but this data can be modified to send any data you wish to send, based on Qubit's event schema:

QubitSDK.tracker().sendEvent(QBEvents.fromJsonString("ecView", viewJson));

where viewJson takes the example form (this may vary depending on custom schema configuration):

{
    "type": "home",
    "subtypes": ["Women", "Dresses", "Cocktail Dresses"]
}

Creating events

QBEvents class provides several methods that allows you to create an event as QBEvent object.

From a json as String:

Example:

String jsonString = "{ \"type\" : \"home\" }";

QubitSDK.tracker().sendEvent(QBEvents.fromJsonString("ecView", jsonString));

From JsonObject:

Example:

JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("type", "home");

QubitSDK.tracker().sendEvent(QBEvents.fromJson("ecView", jsonObject));

From Object:

Example:

public class EcViewEventData {
    private String type;

    // some code
}
EcViewEventData object = new EcViewEventData();
object.setType("home");

QubitSDK.tracker().sendEvent(QBEvents.fromObject("ecView", object));

Enabling/disabling tracking

To disable/enable message dispatch on event occurrence use the following method:

QubitSDK.tracker().enable(false); // disable
QubitSDK.tracker().enable(true); // enable

Note that tracking is enabled by default so you don't need to enable it if you've never disabled it anywhere.

Experiences

SDK contains methods to fetch Experiences. This can be achieved by:

Kotlin snippet:

QubitSDK.tracker().getExperiences(
    experienceIdList = listOfExperienceIds,
    onSuccess = { 
      experienceList -> experienceList.forEach { it.shown() } // make a Post to call the returned callback URL
    },
    onError = { 
      throwable -> Log.e(TAG, "Error: ", throwable) 
    },
    variation = 222,
    preview = false,
    ignoreSegments = true
)

Java snippet:

QubitSDK.tracker().getExperiences(
    listOfExperienceIds,
    experienceList -> {
      for (Experience experience : experienceList) {
        experience.shown(); // make a Post to call the returned callback URL
      }
      return Unit.INSTANCE;
    },
    throwable -> {
      Log.d(TAG, throwable.toString());
      return Unit.INSTANCE;
    }, 222, false, true
);

where variation, preview, ignoreSegments are optional parameters

Tracker Properties

You can get the trackingID and deviceID from the QubitSDK via the following methods:

QubitSDK.getTrackingId();
QubitSDK.getDeviceId();

Backward compatibility

Migration from the previous version of the SDK might be time-consuming and error-prone.

For this reason, in the current SDK you can send events in an exactly same way as before.

Example:

QBTrackingManager.sharedManager().registerEvent("ecView", viewJson);

Note that this class and its methods are deprecated and we recommend to eventually replace them by the new versions (see: Sending events).

Example of how to replace deprecated method of sending events:

QubitSDK.tracker().sendEvent(QBEvents.fromJsonString("ecView", viewJson));

Logging

You can specify which level of logs from SDK do you prefer to print in Logcat. You can do it during initialization (see: Initialization). The default log level is WARN. You can turn off logs by setting SILENT log level.

qubit-sdk-android's People

Contributors

aamq avatar alexolivier avatar hporter avatar jahudzik avatar ljazgar avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.