Google Play

SDK integration

Prerequisites:

  • DTDAnalytics 2.5.0 and higher

dependencies {
    implementation ("com.devtodev:android-google-purchases:*.*.*")
    // Starting from version 6.0.0
    implementation ("com.android.billingclient:billing:*.*.*")
}

To initialize the service, call the startAutoTracking method of the DTDPurchases interface. Call the method after the SDK initialization call:

val config = DTDAnalyticsConfiguration()
DTDAnalytics.initialize("App ID", config, context)
DTDGooglePurchases.initialize(context)
DTDGooglePurchases.startAutoTracking()

Subscription restore

The SDK will automatically restore the list of previously purchased subscriptions at the first launch of the autotracking service. No additional integration is required.

Settings in Google Cloud Platform Console

If you have already activated the Google Play Android Developer API and set up a service account to work with devtodev, you can skip this section and proceed to Pub/Sub service setup.

Google Play Android Developer API

  1. Go to Google Cloud Console under your Google account. Select the project (1) for which you want to configure Google Play Developer API. Then go to the APIs and services section (2).

  1. Go to the Library section.

  1. Find the Google Play Developer API section.

  1. Press ENABLE to enable the Google Play Androd Developer API.

Service account

Go to the Service accounts section.

  1. Select the project to link the service account and where you will collect subscription data later. Create a new project if it is not in the list.

  2. In the list of available service keys, click CREATE SERVICE ACCOUNT.

  3. Fill in the Service account name field. The Service Account ID field will be filled in automatically (use the screenshot below as an example) and click CREATE AND CONTINUE.

    s
  4. Skip the optional steps 2-3 and click DONE at the end of the form.

  5. After creating a service account, you will be returned to the available Service accounts list. Select the created account and open the KEYS tab (1), click ADD KEY (2), and then select the JSON key type option (3) in the pop-up window. Click CREATE to confirm your choice. The generated private key file will be downloaded automatically. You will need to upload this key to devtodev later in the following steps (see Settings on devtodev side).

  6. Go to the IAM section (1) in the Permissions tab and click GRANT ACCESS (2) to add roles to the service account. In the New principals section (3), enter the service account address and grant it the Pub/Sub Subscriber role (4). If you do not have this role, you need to activate the Pub/Sub service in the Cloud Console (activate Pub/Sub API). Save the changes (5).

Pub/Sub service

Go to the list of topics in the Pub/Sub service.

  1. Select the project where you would like to collect subscription data. Click CREATE TOPIC.

  2. To create a topic: fill in the Topic ID (use the screenshot below as an example), disable Add a default subscription option (1) and click CREATE (2).

  3. Select a topic, click on three dots and select View permissions.

  4. Click ADD PRINCIPAL to add the service account.

  5. Add the [email protected] service account and grant it the role of Pub/Sub Publisher. Save the changes.

  6. Open the list of subscriptions and click CREATE SUBSCRIPTION.

  7. In the appeared form:

    • Specify the Subscription ID (1).

    • Fill in the Topic name in Select a Cloud Pub/Sub topic field (2).

    • In the Delivery type select Push (3).

    • Copy Endpoint URL from devtodev (see steps 8-9) and insert it in the Endpoint URL field (4). All other parameters remain unchanged. Save the changes.

  8. To get Endpoint URL, go to devtodev, select the same app and open app settings (Settings → Payments integration → Subscriptions). Click Integrate.

  9. Copy the Endpoint URL and paste it in the corresponding field in Google Cloud (step 7).

Settings on devtodev side

  1. Go to Settings → Payments integration → IAP auto tracking and click edit (3).

  2. Fill in the integration form with the data obtained earlier:

    • Android App ID

    • Upload the Private key file obtained in Service Account step.

    Click Save.

  3. When the integration is complete, the status will change to Active.

  4. If you use subscriptions, go to Payments integration → Subscriptions and click Integrate.

  5. Upload the Private key file obtained in Service Account step (1). Specify Android App ID (2). Add all existing subscriptions, specifying the bundle, subscription period, and name for each subscription. Click Save (3) to finish integration.

Settings in Google Play Console

Service account and User permissions

To set up user permission, you need to log into your Google Play Console account and invite your previously created service account.

  1. In the Users and permissions section, you can add users and manage their permissions.

    • Go to Users and permissions.

    • Click Invite new users.

  2. Add Service Account as a new user:

    • Add your service account email in the Email address field (1).

    • In the Permissions section (2) select the apps (3) accessible to the service account. Click Apply (5). Grant permissions to individual apps, or use account permissions to grant access to all apps in your developer account.

    • Grant the necessary rights to perform actions (see next step Account permissions).

  3. Open Account permissions tab. Grant the following permissions:

    • View app information (1)

    • View app quality information (2)

    • View financial data (3)

    Click Apply to confirm.

Please note that the specified permissions may not apply immediately!

  1. Click Invite user to finish the user setup.

Monetisation setup

After creating a subscription in the Pub/Sub service, you'll need to register the created topic as a target for Real-time developer notifications (RTDN).

  1. Go to the app’s Monetise with Play → Monetisation setup section.

  2. Enter the full name of the topic in the Topic name field.

  3. Tick the Enable real-time notifications checkbox.

  4. Send a test notification using the link below (4). If everything is configured correctly, the test notification will change the integration status of the Subscriptions in devtodev to Active (Settings → Payments integration → Subscriptions → Market connection).

  5. Click Save changes to finish the setup.

Last updated

Was this helpful?