DEV Community

Jackson for HMS Core

Posted on

How to Get Traffic Data for Better Ad Performance

Background

Ads are everywhere and we can't escape them. They're on road billboards, shops, buses and buildings. If a world filled with ads sounds daunting and you want to hide indoors, just beware that ads will even jump out at you from your TV, computer, or phone.

It's likely that ads will be around with us for forever. Ads are often seen as annoying, but they can in fact be very helpful. If you are looking for a job, want to go somewhere fun, or are not sure what special thing you can get for your other half's birthday, ads may in fact provide some inspiration to you.

Nowadays, ads are transforming in appearance and purpose. Ads are becoming more intuitive as they are able to target specific audiences. For example, ads about quick fashion will target young adults, while car ads are typically pushed to automobile enthusiasts. This is an advanced advertising mechanism for brands, media, and users, where all can benefit. Someone gets traffic, someone makes money, and someone gets what they needed. Under ideal conditions, ads, under control and without harmful information spread, mean a lot for us.

As an app developer, I have been trying for a long time to request ads in my app to monetize the traffic and increase revenue. Recently, I encountered some obstacles with the ad traffic monetization data of my own app, and I have been searching for tools to obtain data and analyze ad performance. Collecting such data and then deciding how to analyze ad performance was no easy task, and this was complicated by the many tools and plugins needed to do so. I have used some of the tools found in the industry, but their performance rarely satisfied me.

But I eventually came across a very useful tool, the Publisher Service Reporting API of Ads Kit provided by HMS Core. The traffic monetization service helps me display various ad formats, such as banners, native ads, and rewarded ads, to my users. Routine data tracking is crucial for me to boost revenue. What's more, the Reporting API is key to obtaining ad monetization data, including ad requests, returned ads, impression rate, and click-through rate. I can analyze ad performance based on this data and adjust my monetization strategies accordingly.

But how did I acquire traffic monetization data? Here I'll tell you how I did it.

Implementation Procedure

i. Obtain the client ID and key.

Before obtaining the monetization data, prepare an OAuth 2.0 client ID and key, which are needed for generating the access token passed for calling the Reporting API.

Note that the client ID and key are not those in App information (shown in the following red box) in AppGallery Connect, instead, the client ID and key of the server app created under HMS API services > Credentials on HUAWEI Developers.

Image description

a. Register as a developer and complete identity verification.

Image description

b. Sign in to the console, choose HMS API Services > Credentials, and create a project. If you already have a project, directly select it.

  • Click the drop-down arrow at the top, click New project, fill in the project name and alias, and click OK.

Image description

  • Select the project you created and click OK.

Image description

c. Choose OAuth 2.0 client ID.

Image description

If an OAuth 2.0 client ID and key already exist in your project, you can check whether the product type is server app by clicking Edit in the Operation column of the project. If so, skip step d.

Image description

If your product is not a server app, you should create an OAuth 2.0 client ID.

Image description

d. Select Server app from Product type, set Product name, App type, and Default language, and click Create. In the Note dialog box that displays Client ID and Key, click Confirm.

Image description

e. Go to HMS API services > My APIs, ensure that the project is the one you created, and click Add API from library.

Image description

f. Click Publisher Service Reporting API under App Services.

Image description

g. On the page displayed, click Enable to enable the API. Then you can call the API.

Image description

If you disable it and then enable it again, the setting does not take effect in real time due to page cache, for example. The setting will take about 6 to 10 minutes to take effect. If you have waited for longer time, try again.

ii. Call the Publisher Service Reporting API.

a. Obtain an access token.

Call this API:

POST https://oauth-login.cloud.huawei.com/oauth2/v3/token

Request example:

POST /oauth2/v3/token HTTP/1.1
Host: oauth-login.cloud.huawei.com
Content-Type: application/x-www-form-urlencoded

grant_type=client_credentials&
client_id=<Client ID>&
client_secret=<Client secret>
Enter fullscreen mode Exit fullscreen mode

Screenshot:

Image description

Note that again: the client ID and key are those of the server app but not those of the mobile app created.

b. Call the Reporting API.

POST https://ads.cloud.huawei.com/openapi/monetization/reports/v1/publisher

If you are in Russia, call this API:

POST https://ads-drru.cloud.huawei.ru/openapi/monetization/reports/v1/publisher

Request example:

POST /openapi/monetization/reports/v1/publisher HTTP/1.1
Content-Type: application/json
Authorization: Bearer ***
        Accept: application/json
Content-Length: 233

{
    "start_date": "2022-06-01",
    "end_date": "2022-06-28",
    "filtering": {
        "currency": "CNY"
    },
    "time_granularity": "STAT_TIME_GRANULARITY_DAILY",
    "page": 1,
    "page_size": 10
}
Enter fullscreen mode Exit fullscreen mode

Screenshot:

Image description

As shown in the preceding figure, the data is successfully returned. For more request parameters and response parameters, click here.

In addition, I can customize data display formats to suit my specific app scenarios.

Some Problems You May Encounter

Why was message "access forbidden" returned during the API calling?

Image description

Possible causes:

1) You have not enabled the Reporting API.

2) You have not been authorized to call this API, or your permission has not taken effect yet.

3) The client ID and key used for obtaining the access token are not those of your server app.

My solutions:

i. Click Add API from library under My APIs and enable the Reporting API.

Image description

Image description

Image description

ii. If you disabled and enabled the API again, you may need to wait for 6-10 minutes before the setting takes effect.

iii. Check whether your client ID and key belong to a server app when you obtain the access token. To find out it, check the app type on the Credentials page. If it is not a server app, create one and use its client ID and key to request an access token.

Image description

Image description

Conclusion

Daily advertising data tracking matters very much for app developers, and how to easily get these data is also very important. These data helps me learn about app operations effects in real time, and I can adjust my strategies accordingly. Choosing the right tool or method to do this will make us win more with less work. If you also think obtaining ad monetization data and dealing with ad issues are annoying as me, you can try this tool to help you in subsequent operations. Hope that my procedure and experience can benefit more guys and you can also find out more about useful methods.

Top comments (0)