Skip to main content

Android (Java)

Before I start

Piano Analytics SDKs have been designed for the Piano Analytics solution. Data sent through these SDKs will not be processed within the Analytics Suite 2.


If your Analytics perimeters are certified (ACPM / Mediamétrie), you still need to use the SmartTag SDKs (at least for your pages).

Integrate the library

The first step to use our SDK is to integrate our library in your project. You have multiple ways to do this.


Add this following line in your build.gradle file (app-level) under dependencies:

implementation 'io.piano:analytics:3.x.x' // replace 3.x.x with the version you target


  1. Clone the Android SDK from our Github repository:

    • SSH:
    • HTTPS:
  2. From your Android Studio

    • Go to File > Project Structure > Modules
    • Click on the plus sign + and go to Import...
    • Search for the cloned directory and select the piano-analytics folder
    • Click on Finish
  3. After a sync of Gradle you might have an error like 'Build was configured to prefer settings repositories over project repositories'

    • Open your project-level settings.gradle file and replace/add the repositoriesMode as below
      • repositoriesMode.set(RepositoriesMode.PREFER_SETTINGS)
    • Resync Gradle
  4. As a support to Huawei in our SDK, you might also have a warning on sync (error on build) talking about a library from com.huawei.hms

    • For Gradle plugin earlier than 7.0

      • Open your project-level build.gradle file
      • Add the Maven repository as below under buildscript > repositories and allproject > repositories
        • maven {url ''}
    • For Gradle plugin 7.0

      • Open your project-level build.gradle file
      • Add the Maven repository as below under buildscript > repositories
        • maven {url ''}
      • Open your project-level settings.gradle file
      • Add the Maven repository as below under dependencyResolutionManagement > repositories
        • maven {url ''}
    • For Gradle plugin 7.1 or Later

      • Open your project-level settings.gradle file
      • Add the Maven repository as below under pluginManagement > repositories and dependencyResolutionManagement > repositories
        • maven {url ''}

piano-analytics should now be recognized as a library

Instanciate tracker

Our Android SDK requires you to instanciate a tracker before using it.

You should pass the application context as a parameter.

PianoAnalytics pa = PianoAnalytics.getInstance(getApplicationContext());


In order to setup your tracking, you need to set the configuration of the library:

func PianoAnalytics.setConfiguration(config);

Here is the minimal configuration required:

pa.setConfiguration(new Configuration.Builder()

Don't hesitate to read our collection methods article to find the collection domain that has been assigned to you.

You can also use a custom domain thanks to our CDDC.

Here are the available configurations:

CategoryNameConfigurationBuilder functionDescriptionTypeValue
GlobalcollectDomainwithCollectDomainCollection domainstring
GlobalsitewithSiteSite idint123456789
GlobalpathwithPathRequest pathstringevent
GlobalcustomUserAgentwithCustomUserAgentCustom user agentstringMy User Agent
GlobalcrashDetectionenableCrashDetectionEnable (true) or not (false) automatic crash detectionbooleantrue (default), false
GlobalsessionBackgroundDurationwithSessionBackgroundDurationBackgound delay before considering a session as over (seconds)int30
PrivacyignoreLimitedAdvertisingTrackingenableIgnoreLimitedAdvertisingTrackingWhether the SDK should ignore (true) or not (false) the end-user choice to limit ad tracking.booleantrue, false (default)
PrivacysendEventWhenOptoutenableSendEventWhenOptoutDo you want to send events when optout?booleantrue (default), false
PrivacyprivacyDefaultModewithPrivacyDefaultModePrivacy mode by defaultstringoptin (default)
StorageofflineEncryptionModewithOfflineEncryptionModeOffline feature encryption mode.stringnone, ifCompatible (default), force
StorageofflineStorageModewithOfflineStorageModeOffline feature storage mode. always will always store data, you need to send data yourself required automatically manage offline storage depending on network conditions, never will never store datastringalways, required (default), never
StorageofflineSendIntervalwithOfflineSendIntervalOffline feature interval between sent requestsint500
StoragestorageLifetimePrivacywithStorageLifetimePrivacyLifetime Storage Privacy valueint395 (days)
StoragestorageLifetimeUserwithStorageLifetimeUserLifetime Storage User valueint395 (days)
StoragestorageLifetimeVisitorwithStorageLifetimeVisitorLifetime Storage Visitor valueint395 (days)
StoragevisitorStorageModewithVisitorStorageModeRelative or fixed cookie lifetime value for visitorstringfixed (default), relative
Visitor PolicyvisitorIdTypewithVisitorIdTypeVisitor ID typeConfiguration.VisitorIDTypeConfiguration.VisitorIDType.UUID (default), Configuration.VisitorIDType.ANDROID_ID, Configuration.VisitorIDType.ADVERTISING_ID, Configuration.VisitorIDType.GOOGLE_ADVERTISING_ID, Configuration.VisitorIDType.HUAWEI_OPEN_ADVERTISING_ID, Configuration.VisitorIDType.CUSTOM
Visitor PolicyvisitorIdwithVisitorIDCustom visitor IDstring39001HUFEKK977894


You can find the Android changelog directly on GitHub.