Want Statistics for Your Apps Using the Galaxy Store Developer API?

0
55
Want Statistics for Your Apps Using the Galaxy Store Developer API?


You must have heard about Galaxy Store, where developers sell their apps, themes, and watch faces to Galaxy device users. The Galaxy Store Seller Portal has an amazing tool called Galaxy Store Statistics (GSS). This tool provides information about your sales, revenue, ratings, and much more, which helps you to make more effective business decisions.

If you want to collect this data programmatically, you can use the Galaxy Store Developer (GSD) API. This is a set of server-to-server APIs that allows you to manage apps, manage in-app items, and check app statistics. GSS API is one of these GSD APIs. The GSS API provides programmatic access to some of the statistics in the GSS system. You can get the data you are interested in and view it using your own UI. If your app is being sold in more than one app store, then you can view and compare the data in one page. The GSS API also helps you in data analysis.

What is the GSS API?

There are two types of Galaxy Store Statistics APIs:

  1. GSS User API: This API is required to log in to your seller profile.

  2. GSS Metric API: This API provides statistics for all registered apps and for a particular app.

In this blog article, I show how you can call these APIs and get statistical data from your apps. Since Python is the top choice among major developers, I am going to demonstrate how to implement the GSS APIs using this language. Let’s get started!

Get Started

First, you need to install Python on your PC. The rest of this guide assumes you have already done this.

Prerequisites:

  • Service account ID: Create a seller account in Galaxy Store Seller Portal and get the service account ID. You can find the details here.

  • Authorization: Get the access token from the Galaxy Store authentication server using the accessToken API. Check out this blog to learn about creating the access token using Python.

  • Cookie values: To call any GSS API, four cookie values are required. To get them, log in to Seller Portal and find the cookies using the developer tools of your browser. For more information about retrieving cookie values, check out this guide.

After getting these required values, we are ready to call the GSS APIs.

GSS User API

The seller ID is a required attribute for the sellerMetric API. We can obtain this seller ID by using the loginUserProfile API. The following headers are required to call this API:

Attribute Type Description
content-type string application/json
Authorization string Bearer <your-access-token>
service-account-id header Your service account ID
Cookie string api_server_url, auth_server_url, gss_auth_token, sellerLocale

Let’s start to write the Python script. To make an HTTP request to a specified URL, we need the requests library. So, first we have to import the library in our script.

# Importing the requests library 
import requests 

As mentioned earlier, we need to send some data as the header in our request. Let’s set these values before creating the header:

# Authorization
access_token = "<access_token>" 
Authorization = "Bearer " + access_token 
 
SERVICE_ACCOUNT_ID = "<your-service-account-id>" 
api_url = 'https://devapi.samsungapps.com/gss/user/loginUserProfile' 
 
# Cookie values 
sellerLocale = "<your-seller-locale>"
api_server_url = "eu-auth2.samsungosp.com" 
auth_server_url = "eu-auth2.samsungosp.com"  
 
# Capture before running script  
gss_auth_token = "<gss_auth_token>" 

Let’s create a dictionary using the syntax {key: value}. Here, the key is the attribute name and the value is the header content. All the headers are case-insensitive.

# Header to be sent to API
headers= { 
          'Authorization': Authorization, 
          'content-type': 'application/json', 
          'service-account-id': SERVICE_ACCOUNT_ID,
          'Cookie': "sellerLocale={}; gss_auth_token={};api_server_url={}; auth_server_url={}".format(sellerLocale,gss_auth_token,api_server_url,auth_server_url)
         }

Now, send the HTTP POST request and save the response as a response object. In the response object, we only need the “gssUserId” from “sellerInfo”, so this value is stored as “sellerID”.

try: 
    response = requests.post(api_url, headers=headers)  
    print(response.status_code) 
    print(response.text)  
 
    # Get the seller ID from the response object
    data_shows = response.json()
    sellerID = data_shows["data"]["sellerInfo"]["gssUserId"]
    print(sellerID) 
except Exception as e:
    print(str(e)) 

We have now successfully retrieved the seller ID, which is needed to call the sellerMetric API.

GSS Metric API

The GSS Metric API provides two types of metric APIs: one for viewing the statistics of all the registered apps of a seller and the other for viewing the statistics of one particular app of a seller. Both of these APIs are discussed below.

View seller metrics

The sellerMetric API is a part of the GSS Metric API. This API provides statistics of all apps registered in Galaxy Store for a given seller ID. Currently, this API can show four types of statistics:

  1. New downloads: The number of devices on which users have downloaded the app for the first time.

  2. Downloads by devices: The number of devices on which users have downloaded the app.

  3. Sales: Total income the app has generated.

  4. Item sales: Sales an item has generated.

Each type of statistic has its own metric ID. We have to add the metric ID or IDs in our request to view the specific statistic of all the registered apps. We also have to set a period to view the data in a particular time range. Both the metric ID and time period are mandatory to call this API.

There are numerous ways to view the data of a particular metric ID. For example, we can get a daily trend value, content metadata. and filtered data based on the country or device. It’s also possible to get aggregated data based on the day, week, or month.

First, let’s go through an example where we get all four types of statistics of all registered apps. To compare between a previous period and the current period, two time periods have to be set. Each period is a range of time, denoted by “startDate” and “endDate”. In this example, we set the current period as 8th March to 14th March and the previous period as 1st March to 7th March. We want to see the data based on all countries and devices, so we don’t specify any country or device in the filter attribute. Since we want to see the filtered data, we have to set “getBreakdownsByFilter” to True. Finally, we can show the data aggregated by day.

Let’s start to write the Python script. As we have seen earlier, we need the requests library. So first, let’s import it in our script. We also need to import the json library because we have to send our data as a string.

# Importing the requests library 
import requests   
 
# Importing the json library 
import json 

Next, we need the seller ID, used to identify the seller. We get this value from the loginUserProfile API. I have already discussed how to get this data in a previous section.

Now, create a dictionary to hold the data which will be sent to API. Here, we need to send serialized data in the form of a string and thus json.dumps is necessary to perform the serialization. It is for this reason that we imported the json library earlier.

# Data to be sent to the API 
payload = json.dumps({ 
  "sellerId": sellerID, 
  "periods": [ 
    { 
      "startDate": "2022-03-08", 
      "endDate": "2022-03-14" 
    },   
    {        
      "startDate": "2022-03-01",
      "endDate": "2022-03-07" 
    } 
  ],
  "getDailyMetric": False,
  "getBreakdownsByFilter": True, 
  "noContentMetadata": True, 
  "metricIds": [  
    "total_unique_installs_filter", 
    "revenue_total",  
    "dn_by_total_dvce", 
    "revenue_item"  
  ],   
  "filters": {}, 
  "trendAggregation": "day"  
})   

Finally, define the URL and send the POST request.

# Defining the API endpoint 
seller_metric_url = 'https://devapi.samsungapps.com/gss/query/sellerMetric' 
 
try: 
    response = requests.post(seller_metric_url, headers=headers,data=payload)
    print(response.status_code)
    print(response.text) 
except Exception as e: 
    print(str(e))

The data we are interested in is contained in the response.

View content metrics

The contentMetric API is for retrieving statistics for a specific app or content. Currently, this API can show five types of statistics:

  1. New downloads: The number of devices on which users have downloaded the app for the first time.

  2. Sales: Total income the app has generated.

  3. Item purchases: Number of items purchased and number of canceled payments.

  4. Average rating: Daily average rating this app has received.

  5. Ratings volume: Total number of ratings that have been submitted.

The metric ID and time period are mandatory for this API, just like in the sellerMetric API. We can get filtered data based on the country or device and aggregated data based on the day, week, or month.

I will show you another example to demonstrate this API. In this example, we get all five types of statistics of a particular registered app. First, we set the current period as 2nd May to 2nd July and the previous period as 1st March to 1st May. We want to see the data based on all countries and devices, so we don’t specify any country or device in the filter attribute. We want to see the summary data, so we have to set noBreakdown to True. Finally, we can show the data aggregated by day.

Let’s start to write the Python script, which is largely the same as the sellerMetric API. We just need to change the data which is sent to the API, since the contentMetric API requires the content ID of an app instead of a seller ID. Let’s copy the code from the sellerMetric example and create a dictionary to hold the data to be sent to the API.

payload = json.dumps({  
  "contentId": "<content-id-of-your-app>", 
  "periods": [ 
    {
      "startDate": "2021-05-02",
      "endDate": "2021-07-02" 
    },
    {  
      "startDate": "2021-03-01",
      "endDate": "2021-05-01" 
    } 
  ], 
  "noBreakdown": True, 
  "metricIds": [ 
    "total_unique_installs_filter",
    "revenue_total",  
    "revenue_iap_order_count", 
    "daily_rat_score",   
    "daily_rat_volumne"  
  ], 
  "filters": {}, 
  "trendAggregation": "day" 
})  

Finally, define the URL and send the POST request.

# Defining the API endpoint  
content_metric_url = 'https://devapi.samsungapps.com/gss/query/contentMetric'
 
try:
    response = requests.post(content_metric_url, headers=headers,data=payload)
    print(response.status_code)
    print(response.text)  
except Exception as e:  
    print(str(e))   

Conclusion

We have learned how to get the seller ID, statistics of all apps for a given seller, and statistics for a specific app. You can keep a record of these statistics which can be helpful for your business in many ways. For example, based on this data, you can promote your app in a specific country, provide offers and give recommendations to new users. You can find more information about the GSS system here (you must be logged in to your Seller Portal account to view this documentation). You can also ask questions in the Samsung Developer forum.

Blog articles in this series

  • How to Create an Access Token for the Galaxy Store Developer API Using Python: Learn how to create an access token using the Galaxy Store Developer API and Python.

  • How to manage content (coming soon): We can manage our content in Galaxy Store by using the Content Publish API. In an app production system, managing content is a frequent task. This blog will cover the implementation of this API using Python to automate your app production system.

  • How to update in-app items (coming soon): If your content has in-app items, then this blog is recommended for you. IAP Publish API allows you to view, register, modify, and remove Samsung In-App Purchase items programmatically. In this blog, implementation of this API will be demonstrated.



Source link

Leave a reply

Please enter your comment!
Please enter your name here