[Huawei Developers] John Wo:
After learning how to release a Cocos-based app in HUAWEI AppGallery Connect, you can monitor your app's performance data using AppGallery Connect APM. Currently, the APM SDK supports only the Android platform. Take APM as an example. Let's see how to integrate a service.

Configuring Relevant Information in Cocos Creator

1. On the Service panel of Cocos Creator, find and enable APM.

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/006/560/358/2640852000006560358.20201028014701.24640500243116627882512691710389:50511109073442:2800:B4CA4AE9CDA82BAE4CC0A4B01F318ECA313F4C1042EAE79D3BFF5601F039EE8A.jpg"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/006/560/358/2640852000006560358.20201028014701.24640500243116627882512691710389:50511109073442:2800:B4CA4AE9CDA82BAE4CC0A4B01F318ECA313F4C1042EAE79D3BFF5601F039EE8A.jpg[/IMG]

2. Before integrating a service, you need to associate the service with an app. Click Association. In the dialog box that is displayed, click Create. The Cocos console is displayed.

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/006/560/358/2640852000006560358.20201028014724.75405968997274446761375495280951:50511109060450:2800:8E02FFACD9FDECD0B2DC535C4C3CA474B1532784F357A75F8C564FE0C481323A.jpg"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/006/560/358/2640852000006560358.20201028014724.75405968997274446761375495280951:50511109060450:2800:8E02FFACD9FDECD0B2DC535C4C3CA474B1532784F357A75F8C564FE0C481323A.jpg[/IMG]

3. On the Cocos console, create a game.

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/006/560/358/2640852000006560358.20201028014849.10240166616940837338338928458004:50511109060450:2800:C1A5540ACA5673E3901A407132015BEE955D9D695178D0BB4D2EE2D5129E21AC.jpg"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/006/560/358/2640852000006560358.20201028014849.10240166616940837338338928458004:50511109060450:2800:C1A5540ACA5673E3901A407132015BEE955D9D695178D0BB4D2EE2D5129E21AC.jpg[/IMG]

4. Go back to Cocos Creator and create, refresh, or select an association.

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/006/560/358/2640852000006560358.20201028014858.94112879866767249264225974318034:50511109060450:2800:F7388B458F1671485B3D4911E38D9971B53B80D0B141700302B0F778DDB84D7E.jpg"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/006/560/358/2640852000006560358.20201028014858.94112879866767249264225974318034:50511109060450:2800:F7388B458F1671485B3D4911E38D9971B53B80D0B141700302B0F778DDB84D7E.jpg[/IMG]

Configuring Relevant Information in AppGallery Connect

1. Sign in to AppGallery Connect, click My projects, and find your project, and click the game you created last time on the project card.

2. Go to Quality > APM and click Enable.

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/006/560/358/2640852000006560358.20201028015014.33380804407865912824046734518494:50511109060450:2800:58FCCD535EBA2CD92F75411F80CC905BD445CDCBCE5544AB5C7E2A895FEDB340.jpg"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/006/560/358/2640852000006560358.20201028015014.33380804407865912824046734518494:50511109060450:2800:58FCCD535EBA2CD92F75411F80CC905BD445CDCBCE5544AB5C7E2A895FEDB340.jpg[/IMG]

3. Go to Project settings and download the latest agconnect-services.json file.

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/006/560/358/2640852000006560358.20201028015036.29021721102911171988459335501622:50511109060450:2800:14C1592BD6C8B6574789495EC4FDEB6118BE047C946967ADACE5BDC3BD10ABE7.jpg"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/006/560/358/2640852000006560358.20201028015036.29021721102911171988459335501622:50511109060450:2800:14C1592BD6C8B6574789495EC4FDEB6118BE047C946967ADACE5BDC3BD10ABE7.jpg[/IMG]

4. Save the downloaded agconnect-services.json file to the settings directory in your Cocos project.

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/006/560/358/2640852000006560358.20201028015051.81153888495365775853042437760369:50511109060450:2800:C6E6D8D4E85288CB63A3551B31DEF10471D0EF255921F44AE8BA0A7C4624D484.jpg"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/006/560/358/2640852000006560358.20201028015051.81153888495365775853042437760369:50511109060450:2800:C6E6D8D4E85288CB63A3551B31DEF10471D0EF255921F44AE8BA0A7C4624D484.jpg[/IMG]

Packaging and Running an App

Currently, AppGallery Connect APM does not provide a JavaScript SDK. Therefore, you need to package your app and install it on an Android device to view its performance data. Perform the following steps:

1. Package the current Cocos-based app. Access Cocos Creator, go to Project > Build..., choose HUAWEI AppGallery Connect, and set a package name.

Note: The package name must be the same as the package name configured in AppGallery Connect, that is, the name of the JSON file in the previous step. Otherwise, a compilation error is reported.

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/006/560/358/2640852000006560358.20201028015108.39009078740666870367944104526574:50511109060450:2800:7BB611C80BF680D7DF22DED6D77BCCFCFA2E73A41176E0E458DF31B3EA00EB53.jpg"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/006/560/358/2640852000006560358.20201028015108.39009078740666870367944104526574:50511109060450:2800:7BB611C80BF680D7DF22DED6D77BCCFCFA2E73A41176E0E458DF31B3EA00EB53.jpg[/IMG]

2. Find the corresponding APK file in the \build\jsb-link\publish\android directory of the project.

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/006/560/358/2640852000006560358.20201028015126.54898212643063354853696206414332:50511109060450:2800:2A589F7823373042DC30B6B56BFCC3F06477D907BAE8EF8D9E97E82BA60BC574.jpg"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/006/560/358/2640852000006560358.20201028015126.54898212643063354853696206414332:50511109060450:2800:2A589F7823373042DC30B6B56BFCC3F06477D907BAE8EF8D9E97E82BA60BC574.jpg[/IMG]

3. Install the file on an Android device by running the adb install –r packageName.apk command in the CLI.

4. Launch the app and perform normal operations. Check whether the corresponding APMS logs are generated. If so, you have integrated the APM service successfully.

Viewing App Performance Data

After the app runs for about 5 minutes, you can view its performance data in AppGallery Connect (under My projects > Quality > APM). For details, check Viewing App Performance Data.

[IMG="https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/006/560/358/2640852000006560358.20201028015208.39775170040254340624247615336352:50511109060450:2800:58E055023236FE1CF7FB73C39EA4DE39E4E850EEF2F5FAE1AFCF8BE833F16E95.jpg"]https://communityfile-dre.op.hicloud.com/FileServer/getFile/cmtybbs/006/560/358/2640852000006560358.20201028015208.39775170040254340624247615336352:50511109060450:2800:58E055023236FE1CF7FB73C39EA4DE39E4E850EEF2F5FAE1AFCF8BE833F16E95.jpg[/IMG]

Additional APM Features

In addition to the basic features, APM has some additional features, including custom tracing parameters. You can use these features to monitor app performance in specific scenarios, such as app sign-in and ANR problems.

1. Setting custom tracing parameters:

huawei.agc.apms.apmsService.startCustomTrace("traceID");

2. Setting the attribute names and values of a custom trace:

huawei.agc.apms.apmsService.putCustomTraceProperty(traceID, pName, pValue);

3. Creating a network request indicator instance for each network request to collect network performance data:

let id = huawei.agc.apms.apmsService.initNetworkMeasure(url, "POST");
console.log("createNetworkMeasure, id = ", id);

For more details, you can go to:

APM (AppGallery Connect) quick start for a Cocos-based app:

https://docs.cocos.com/creator/manual/en/cocos-service/agc-apm.html

AppGallery Connect APM development guide:

https://developer.huawei.com/consumer/en/doc/development/AppGallery-connect-Guides/agc-apms-introduction

Cocos Creator Integrates with AppGallery Connect APM – Releasing a Cocos-based App:

https://developer.huawei.com/consumer/en/forum/topicview?fid=0101271690375130218&tid=0203359161844040878&pid=0303359161844040067