## tenjin

This service integrates your Android project with https://www.tenjin.com/[Tenjin], an install attribution service.

See https://docs.tenjin.com/[Tenjin docs] for an overview of what Tenjin offers. It is a commercial service, although can be used for free with some limits.

You will need to:

- Create an account on https://www.tenjin.com/[Tenjin], add your game (for Android), and get the API key from https://www.tenjin.io/dashboard/[Tenjin dashboard] (this step is similar as for iOS).

- You also need to allow Tenjin to verify purchases done on Google Play. See https://github.com/tenjin/tenjin-android-sdk#purchase-events[Tenjin Android docs], section _"Purchase Events"_.

### Declare in CastleEngineManifest.xml

Declare it like this in link:https://castle-engine.io/project_manifest[CastleEngineManifest.xml]:

[source,xml]
----
<?xml version="1.0" encoding="utf-8"?>
<project name="..." game_units="...">
  <android>
    <services>
      <service name="tenjin" />
    </services>
  </android>
</project>
----

### Use from Pascal

*(Note that working with Tenjin on Android and iOS is the same from Pascal, so you can use a single code to handle both.)*

Create a single instance of `TCastleTenjin` class (from `CastleTenjin` unit). You can do this e.g. in the `Application.OnInitialize` callback. You can use the fact that `TCastleTenjin` descends from `TComponent`, and set the owner of it to be `Application`, to make it freed automatically.

Then initialize the analytics reporting. Make sure to ask users for permission to collect data, in particular in EU where GDPR is in effect. Make sure to mention this in your application's privacy policy too.

Like this:

[source,pascal]
----
var
  MyTenjin: TCastleTenjin;

procedure ApplicationInitialize;
begin
  ...

  MyTenjin := TCastleTenjin.Create(Application);
  MyTenjin.Initialize('YOUR-TENJIN-API-KEY');
end;
----

Optionally you can also send custom events to Tenjin. Just call from anywhere `MyTenjin.SendEvent('event_name');`.

### Using Android Advertising ID (AAID)

The _Tenjin_ service does use _Android Advertising ID (AAID)_.

We declare the `com.google.android.gms.permission.AD_ID` permission in the application.

On _Google Play_, in the corresponding survey, you have to answer _Yes_ when asked whether the app uses _Android Advertising ID (AAID)_.
