Firebase backend reports event event-based on measurement protocol

Firebase backend reports event event-based on measurement protocol

Foreword:

We know that Firebase is a set of mobile application and web application development platforms provided by Google. The app only needs to integrate its sdk to automatically report default events. This article will introduce how to report backend buried points to firebase, and record some problems I encountered.

Solution steps:

  1. At the beginning, my preferred solution was to report by integrating the firebase backend sdk, because I have also connected with firebase's third-party service authentication, message push and other functions before, which is very convenient, just introduce dependencies like this:

    <dependency>
      <groupId>com.google.firebase</groupId>
      <artifactId>firebase-admin</artifactId>
      <version>8.1.0</version>
    </dependency>
    

    However, after checking the information and documents, it is found that the firebase backend sdk does not support event reporting. So far, the new feature suggestion of its open source forum: adding backend reporting has not yet been implemented.

    insert image description here

    It can only be reported through the measurement protocol rest-api: document address

    insert image description here
    As shown in the figure, this interface requires two mandatory parameters, api_secret and measurement_id. The following describes how to obtain

  2. First register your own google account to enter the firebase background , and create your own project and application. **Note that this must be a web-type application, because only web-type applications will have a measurement_id measurement id. **Maybe a friend will ask, what if my application is an app? It doesn’t matter. The event reported here is the project dimension, so as long as it is an application under this project, it will do.
    insert image description here

  3. Then go to the analytics background to find the parameters we need: the setting button in the lower left corner -> data flow -> web application -> measurement id, Measurement Protocol API key to generate
    insert image description here

  4. Let's look at a specific request example:

    curl --location 'https://www.google-analytics.com/mp/collect?measurement_id=G-***&api_secret=***' \
    --header 'Content-Type: application/json' \
    --data '{
        "client_id": "x123",
        "user_id":"123",
        "timestamp_micros":1694161347000000,
        "events": [
            {
                "name": "test_localsend1",
                "params": {
                    "engagement_time_msec": "100",
                    "session_id": "123"
                }
            }
        ]
    }'
    

    For the parameter format, you can read the above interface document in detail and upload it as needed.

  5. Firebase background effect display:
    insert image description hereThe event statistics in the Events column will not be displayed in real time, usually within 24 hours. The two events in the above picture were uploaded yesterday, but they are only displayed today!
    Realtime insert image description hereAnalytics real-time analysis can be displayed in real time

  6. If the income field is reported. After some research, it is found that the revenue must be passed through a specific event such as: in_app_purchase, but only the app that integrates the sdk can report this event, and the back-end report is directly ignored. Currently, there is no alternative solution, and there are friends who know You can leave a message in the comment area~

Guess you like

Origin blog.csdn.net/Arhhhhhhh/article/details/132599839