Cannot receive events from Google Measurement Protocol (Google Analytics v4)

Viewed 323

I created an app in Firebase, and then found my target app (NodeJS CLI, Chrome extension, VSCode extension) could not use Firebase SDK, then I found the Google Measurement Protocol. And it turns out to be frustrating and failed to get events to show up in the console.

My request passed /debug/mp.collect:

fetch(
    `https://www.google-analytics.com/mp/collect?api_secret=${SECRET}&firebase_app_id=${FIREBASE_APP_ID}`,
    {
      method: 'POST',
      body: JSON.stringify({
        app_instance_id: ${INSTANCE_ID},
        events,
      }),
    }
  )

1st problem I met is finding the api_secret

Official doc says:

An API SECRET generated in the Google Analytics UI. To create a new secret, navigate to: Admin > Data Streams > choose your stream > Measurement Protocol > Create

What I get is: enter image description here

OK then comes into firebase:

const firebaseConfig = {
  apiKey: "xxx",
  authDomain: "dev-ext.firebaseapp.com",
  databaseURL: "https://dev-ext.firebaseio.com",
  projectId: "test",
  storageBucket: "dev-ext.appspot.com",
  messagingSenderId: "123",
  appId: "xxx",
  measurementId: "xxx"
};

Looks like is this apiKey, and I tried, not working.

Then I found someone says use the secret here: enter image description here

And I tried, not working.

2nd problem is the app_instance_id, what the hell is this?

Here is the original doc:

enter image description here

No clues for web and NodeJS case at all, and the ios, android links are pointing to Firebase SDK method. I was like "WTF, why will I read this if I could use the Firebase SDK?"

So I tried a generated uuid. And obviously, it's not working.

1 Answers

I have the same, issue. Ended up adding a new stream on analytics.google.com and switching to gtag.js.

Related