Send Data to Google Analytics

Developers can now send data from MoEngage to Google Analytics tool using our Connectors via GA Measurement Protocol.

Google Analytics Measurement Protocol allows developers to make HTTP requests to send raw user interaction data directly to Google Analytics servers. This in turn enables developers to measure how users interact with their business from almost any environment. Developers can then use the Measurement Protocol to:

  • Measure user activity in new environments.
  • Tie online to offline behavior.
  • Send data from both the client and server.

Measurement Protocol (Universal Analytics)

The base url to make the API Request is http://www.google-analytics.com/collect with Request Type as POST.

Screen_Shot_2017-04-27_at_3.49.34_PM.png

You can read more details here about the parameters that can be used with Google Measurement Protocol.

Say you want to track an event on Google Analytics, the sample URL params are:

Screen_Shot_2017-04-27_at_3.22.23_PM.png

The used keys represent: 

ec - Event Category Name

ea - Event action name

el -  Event Label

ev - Event Value

The resulting URL will be: http://www.google-analytics.com/collect?v=1&tid=UA-12345678-9&cid=545432&t=event&ec=samplecategory&ea=sampleaction&el=samplelabel&ev=1234.

You can copy this directly and paste in "Webhook URL" field of MoEngage Connector campaign and change and test as per your use case.

Measurement Protocol (Google Analytics 4)

Google Analytics 4 only supports POST calls. To send an event, make a HTTP POST request to the following endpoint:

POST /mp/collect HTTP/1.1
HOST: www.google-analytics.com
Content-Type: application/json
<payload_data>

Data is sent to Google Analytics using the Measurement Protocol Data in two parts:

  1. Query parameters
  2. A JSON POST body

Query Parameters

Parameter Name Description
api_secret

Required. 

An API Secret that is generated through the Google Analytics UI. An API Secret that is generated through the Google Analytics UI.

To create a new secret, navigate in the Google Analytics UI to:

Admin > Data Streams > choose your stream > Measurement Protocol > Create

measurement_id

Optional.

Measurement ID. The identifier for a Data Stream. Found in the Google Analytics UI under:

Admin > Data Streams > choose your stream > Measurement ID

firebase_app_id

Required only if using a Firebase app. 

Firebase App ID. The identifier for a Firebase app. Found in the Firebase console under:

Project Settings > General > Your Apps > App ID

Read more about the required query parameters of the Measurement Protocol.

The payload of your request depends on the events and attributes that you want to track. Below are the required fields:

Parameter Name Description
client_id

Required only if using gtag.js. 

Uniquely identifies a user instance of a web client. See send event to the Measurement Protocol.

app_instance_id

Required only if using a Firebase app.

Uniquely identifies a specific installation of a Firebase app. This value needs to be retrieved through the Firebase SDK.

events

Required. 

An array of event items.

Read more about the required JSON post-body parameters of the Measurement Protocol.

Setting up a connector campaign

To create a connector campaign on MoEngage, 

  1. Navigate to Create Campaign >> Connectors >> Custom and choose the delivery type as "Event-Triggered".

Screenshot_2022-02-21_at_10.48.46_PM.png

  1. Give your campaign a name and relevant tags.
  2. Configure your trigger criteria. You can optionally choose to add a delay as well.

  1. Choose your target audience. You can also check the count of your audience. 

  1. Click next to proceed to the next step.
  2. On step 2 of the campaign,
    • Select the method as POST.
    • Add Webhook URL as : https://www.google-analytics.com//mp/collect?api_secret=<api_secret>&measurement_id=<measurement_id>
    • The URL parameters list should auto-populate. Replace <api_secret> with your API Secret Key. You can swap this parameter with firebase_app_id if you're using a Firebase app. Replace <measurement_id> with the ID of your Data Stream.
    • In Headers, add Content-Type as application/json.
    • In Body, choose Raw and use the content depending on what events you want to send to Google Analytics. Below is an example:
      {
          "client_id": "<client_id>",
          "user_id": "{{UserAttribute['ID']}}",
          "timestamp_micros": "{{EventAttribute['Event Time (UTC)']}}",
          "user_properties": {
              "email": {
                  "value": "{{UserAttribute['Email (Standard)']}}"
              }
          },
          "events": [
              {
                  "name": "cart_checkout",
                  "params": {
                      "checkout_value": 1000
                  }
              }
          ]
      }
      • Make sure to replace <client_id> with the client ID (if using gtag.js). You can also swap this key with app_instance_id if you're using a Firebase app.

  1. At this point, your campaign should be ready to test and send. You can also test your connector configuration using the Test functionality available in Step 2 of Create Connector Campaign.

Screen_Shot_2022-02-22_at_11.12.42_AM.png

If your Google Analytics account successfully receives the event, your set-up is good to go. You can go ahead and Publish the campaign.

Was this article helpful?
3 out of 5 found this helpful

How can we improve this article?