AppMetrica

Send in-app subscription and purchases events to AppMetrica

Qonversion sends subscription events to AppMetrica to help you match your users' behavior with their payment history and inform your product decisions.

1. Setup the SDKs

  1. Make sure you have AppMetrica SDK installed. More about the AppMetrica SDKs read here.

  2. Set Qonversion SDK by following installing the SDK guide.

  3. To attribute sent from Qonversion events to a particular AppMetrica user, set AppMetrica Device ID:

    let completionBlock: (String?, Error?) -> Void = { deviceId, error in
      if let error = error {
        // Handle error here
      } else if let deviceId = deviceId {
        Qonversion.shared().setUserProperty(.appmetricaDeviceId, value: deviceId)
      }
    }
    
    // Specify the dispatch queue on which you want to execute the completion block, main queue as an example
    let queue = DispatchQueue.main // Use the main queue as an example
    
    YMMYandexMetrica.requestAppMetricaDeviceID(withCompletionQueue: queue, completionBlock: completionBlock)
    
    YMMAppMetricaDeviceIDRetrievingBlock completionBlock = ^(NSString * _Nullable deviceId, NSError * _Nullable error) {
      if (error) {
        // Handle error here
      } else {
        [[Qonversion sharedInstance] setUserProperty:QONUserPropertyKeyAppMetricaDeviceId, value: deviceId];
      }
    };
    
    // Specify the dispatch queue on which you want to execute the completion block, main queue as an example
    dispatch_queue_t queue = dispatch_get_main_queue();
    
    [YMMYandexMetrica requestAppMetricaDeviceIDWithCompletionQueue:queue
                                                   completionBlock:completionBlock];
    
    StartupParamsCallback startupParamsCallback = new StartupParamsCallback() {
        @Override
        public void onReceive(@Nullable Result result) {
            if (result != null) {
                // Note, that `deviceIdHash` is used, not `deviceId`
                Qonversion.getSharedInstance().setUserProperty(QUserPropertyKey.AppMetricaDeviceId, result.deviceIdHash);
            }
        }
    
        @Override
        public void onRequestError(@NonNull Reason reason, @Nullable Result result) {
            // ...
        }
    };
    AppMetrica.requestStartupParams(
            this,
            startupParamsCallback,
            Arrays.asList(
                    // Note, that `APPMETRICA_DEVICE_ID_HASH` is used, not `APPMETRICA_DEVICE_ID`
                    StartupParamsCallback.APPMETRICA_DEVICE_ID_HASH
            )
    );
    
    val startupParamsCallback = object : StartupParamsCallback {
        override fun onReceive(result: StartupParamsCallback.Result?) {
            // Note, that `deviceIdHash` is used, not `deviceId`
            result?.deviceIdHash?.let {
                Qonversion.shared.setUserProperty(QUserPropertyKey.AppMetricaDeviceId, it)
            }
        }
    
        override fun onRequestError(
            reason: StartupParamsCallback.Reason,
            result: StartupParamsCallback.Result?
        ) {
            // Handle error here
        }
    }
    AppMetrica.requestStartupParams(
        this,
        startupParamsCallback,
        listOf(
            // Note, that `APPMETRICA_DEVICE_ID_HASH` is used, not `APPMETRICA_DEVICE_ID`
            StartupParamsCallback.APPMETRICA_DEVICE_ID_HASH
        )
    )
    
    String deviceId = await AppMetrica.requestAppMetricaDeviceID();
    Qonversion.getSharedInstance().setUserProperty(QUserPropertyKey.appMetricaDeviceId, deviceId);
    
    AppMetrica.requestAppMetricaDeviceID((deviceId, reason) => {
      if (deviceId) {
        Qonversion.getSharedInstance().setUserProperty(UserPropertyKey.APP_METRICA_DEVICE_ID, deviceId);
      } else {
        // Handle error here
      }
    });
    
    AppMetrica.Instance.RequestAppMetricaDeviceID((deviceId, error) =>
        {
            if (error != null)
            {
                // Handle error here
            }
            else
            {
                Qonversion.GetSharedInstance().SetUserProperty(UserPropertyKey.AppMetricaDeviceId, deviceId);
            }
        });
    
  4. (Optionally) To improve attribution quality, set the same user ID to AppMetrica and Qonversion SDKs:

    YMMYandexMetrica.setUserProfileID("yourSideUserID")
    Qonversion.shared().setUserProperty(.appMetricaUserProfileId, value: "yourSideUserID")
    
    [YMMYandexMetrica setUserProfileID:@"yourSideUserID"];
    [[Qonversion sharedInstance] setUserProperty:QONUserPropertyKeyAppMetricaUserProfileId, value: @"yourSideUserID";
    
    AppMetrica.setUserProfileID("yourSideUserID");
    Qonversion.getSharedInstance().setUserProperty(QUserPropertyKey.AppMetricaUserProfileId, "yourSideUserID");
    
    AppMetrica.setUserProfileID("yourSideUserID")
    Qonversion.shared.setUserProperty(QUserPropertyKey.AppMetricaUserProfileId, "yourSideUserID")
    
    await AppMetrica.setUserProfileID('yourSideUserID');
    Qonversion.getSharedInstance().setUserProperty(QUserPropertyKey.appMetricaUserProfileId, 'yourSideUserID');
    
    AppMetrica.setUserProfileID('yourSideUserID');
    Qonversion.getSharedInstance().setUserProperty(UserPropertyKey.APP_METRICA_USER_PROFILE_ID, 'yourSideUserID');
    
    AppMetrica.Instance.SetUserProfileID("yourSideUserID");
    Qonversion.GetSharedInstance().SetUserProperty(UserPropertyKey.AppMetricaUserProfileId, "yourSideUserID");
    

2. Configure the AppMetrica integration

  1. Navigate to your AppMetrica dashboard, select Settings and collect the following keys:

    1. Application ID. It can be found right below the Application name in the General tab.
    2. Post API key. It can be found in the General settings section as well.
  1. Navigate to the Integrations section of your Qonversion project, select AppMetrica, provide the Application ID and Post API key, and click Save.
  1. You can use the default event names provided by Qonversion or change them as you need.

Read more about tracked events here

👍

Done

Now Qonversion starts sending in-app purchases and subscription data to your AppMetrica account.

Event Payload

In case you need details about data sent to AppMetrica, follow the example below:

{
  "post_api_key": "your_post_api_key",
  "application_id": "your_application_id",
  "revenue_event_type": "example_event_type",
  "event_timestamp": "1707206995",
  "product_id": "example_product_id",
  "app_package_name": "com.example.app",
  "appmetrica_device_id": "8f65b16df378e7a6bece9614e1530fb55",
  "price": "19.99",
  "currency": "USD",
  "transaction_id": "example_transaction_id",
  "order_id": "example_order_id",
  "ios_ifa": "example_advertising_id_for_ios",
  "google_aid": "example_advertising_id_for_android",
  "os_name": "iOS",
  "os_version": "15.0",
  "device_model": "iPhone13,2",
  "device_locale": "en_US",
  "app_version_name": "1.0.0"
}