目录

Performing Debugging

The app attribution service provides the debugging capability. You can perform debugging by calling the debugging API to ensure a smooth interworking process and verify the basic capabilities of attribution postback, thereby improving efficiency.

Use Cases

The debugging capability supports the following scenarios:

API Description

The app attribution service provides the following debugging-related APIs. For details, please refer to the API reference.

API Description
validateSource(adSourceInfo: AdSourceInfo, publicKey: string): Promise<void> Verifies the attribution sources; used by media apps and distribution platforms to verify the validity of the input parameter adSourceInfo.
setPostback(postbackInfo: PostbackInfo): Promise<void>

Sets the attribution result, allowing you to:

- Verify the validity of triggerData.

- Configure the postback data used for debugging.

flushPostbacks(adTechId: string): Promise<void> Triggers attribution postback in a proactive and real-time manner, allowing you to verify the logic for receiving and processing postback data.

Development Procedure

[h2]Verifying Attribution Sources

  1. Import required modules.

    import { BusinessError, deviceInfo } from '@kit.BasicServicesKit';
    import { hilog } from '@kit.PerformanceAnalysisKit';
    import { SignUtil } from '../common/utils/SignUtil';
    import { util } from '@kit.ArkTS';
    // ...
    import { attributionTestManager } from '@kit.AppGalleryKit';
  2. Construct input parameters: AdSourceInfo and publickey.

    // Public key and the corresponding private key provided during role registration on the cloud platform of the app attribution service.
    let privateKey: string = '';
    let publicKey: string = '';
    // You can enter a virtual adTechId. The value must contain eight characters.
    let adTechId: string = '1******8';
    // ID of the ad task created by the ad platform.
    // Starting from API version 12, the value of campaignId cannot exceed six characters.
    // Starting from API version 22, the value of campaignId cannot exceed nine characters.
    let campaignId: string = '';
    let osApiVersion: number = deviceInfo.sdkApiVersion;
    if (osApiVersion >= 22) {
        campaignId = '1*******9';
    } else {
        campaignId = '1****6';
    }
    // ID of the developer's app released on AppGallery, without letter C.
    let destinationId: string = '1******8';
    // ID of the attribution monitoring platform.
    let mmpIds: string[] = ['1******8', '2******9'];
    // Business information relevant to the distribution platform.
    let serviceTag: string = 'testServiceTag';
    // Random string without hyphens (-), used for signature calculations.
    let nonce: string = util.generateRandomUUID().replace(/-/g, '');
    // Timestamp.
    let timestamp: number = Date.now()
    let adSourceInfo: attributionTestManager.AdSourceInfo = {
        adTechId: adTechId,
        campaignId: campaignId,
        destinationId: destinationId,
        // Impression.
        sourceType: attributionTestManager.SourceType.IMPRESSION,
        mmpIds: mmpIds,
        serviceTag: serviceTag,
        nonce: nonce,
        timestamp: timestamp,
        // Signature.
        signature: await SignUtil.getSign(this.getUIContext(),
            SignUtil.genSignContent(adTechId, campaignId, destinationId, mmpIds, serviceTag, nonce, timestamp),
            privateKey)
    };
  3. Call the attributionTestManager.validateSource method to verify attribution sources.

    try {
        // ...
        await attributionTestManager.validateSource(adSourceInfo, publicKey);
        hilog.info(0, TAG, 'validateSource success.');
        // ...
    } catch (error) {
        hilog.error(0, TAG, `validateSource error. code is ${error.code}, message is ${error.message}`);
        // ...
    }

[h2]Configuring Attribution Result Postback

  1. Import required modules.

    import { BusinessError, deviceInfo } from '@kit.BasicServicesKit';
    import { hilog } from '@kit.PerformanceAnalysisKit';
    // ...
    import { attributionTestManager } from '@kit.AppGalleryKit';
  2. Construct an input parameter PostbackInfo.

    // ID of the ad task created by the ad platform.
    // Starting from API version 12, the value of campaignId cannot exceed six characters.
    // Starting from API version 22, the value of campaignId cannot exceed nine characters.
    let campaignId: string = '';
    let osApiVersion: number = deviceInfo.sdkApiVersion;
    if (osApiVersion >= 22) {
        campaignId = '1*******9';
    } else {
        campaignId = '1****6';
    }
    let postbackInfo: attributionTestManager.PostbackInfo = {
        // Attribution role ID of a distribution platform, which is allocated by the app attribution service during role registration on the cloud platform of the app attribution service.
        adTechId: '1******8',
        campaignId: campaignId,
        // ID of the developer's app released on AppGallery, without letter C.
        destinationId: '1******8',
        // Media app ID.
        sourceId: '1******8',
        // Business information relevant to the distribution platform.
        serviceTag: 'testServiceTag',
        triggerData: 123,
        businessScene: 5,
        // Server URL for postback.
        postbackUrl: 'xxx.com'
    };
  3. Call the attributionTestManager.setPostback method to set the attribution result data to be posted back.

    try {
        // ...
        await attributionTestManager.setPostback(postbackInfo);
        hilog.info(0, TAG, 'setPostback success.');
        // ...
    } catch (error) {
        hilog.error(0, TAG, `setPostback error. code is ${error.code}, message is ${error.message}`);
        // ...
    }

[h2]Triggering Attribution Result Postback

  1. Import required modules.

    import { BusinessError, deviceInfo } from '@kit.BasicServicesKit';
    import { hilog } from '@kit.PerformanceAnalysisKit';
    // ...
    import { attributionTestManager } from '@kit.AppGalleryKit';
  2. Construct the adTechId parameter.

    let adTechId: string = '1******8';
  3. Call the attributionTestManager.flushPostbacks method to trigger the postback of attribution results.

    try {
        // ...
        await attributionTestManager.flushPostbacks(adTechId);
        hilog.info(0, TAG, 'flushPostbacks success.');
        // ...
    } catch (error) {
        hilog.error(0, TAG, `flushPostbacks error. code is ${error.code}, message is ${error.message}`);
        // ...
    }