thomaskutama

PEPETA KE Measurement Protocol | confirmation deposit placed | Firebase

Jul 7th, 2026
33
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const firebaseAppId = '1:195791133910:android:15d07d414fec1e69807d77';
  2. const apiSecret = 'Gi6MLUDRTE-vpahlx-sbcw';
  3.  
  4. fetch(`https://www.google-analytics.com/mp/collect?firebase_app_id=${firebaseAppId}&api_secret=${apiSecret}`, {
  5.   method: "POST",
  6.   headers: {
  7.     "Content-Type": "application/json"
  8.   },
  9.   body: JSON.stringify({
  10.     "app_instance_id": appInstanceId,       // String: Must be retrieved from the Android SDK
  11.     "user_id": userId,                       // String: Your internal unique user ID
  12.     "timestamp_micros": timestampMicros,     // String: Unix epoch timestamp in microseconds
  13.     "events": [
  14.       {
  15.         "name": "confirmation_deposit_placed",
  16.         "params": {
  17.           "session_id": sessionId,           // String: GA4 session ID from the app client
  18.           "deposit_id": depositId,           // String: Unique identifier for the transaction
  19.           "currency": currencyCode,           // String: 3-letter ISO 4217 code (e.g., "UGX", "USD")
  20.           "value": depositValue              // Numeric: Double or Integer (do NOT wrap in quotes)
  21.         }
  22.       }
  23.     ]
  24.   })
  25. })
  26. .then(response => {
  27.   // GA4 explicitly returns a 204 No Content on a successful payload validation
  28.   if (response.status === 204) {
  29.     console.log("GA4 Event successfully dispatched.");
  30.   } else {
  31.     console.error(`GA4 Error Status: ${response.status}`);
  32.   }
  33. })
  34. .catch(error => console.error("Network error reporting to GA4:", error));
Advertisement
Add Comment
Please, Sign In to add comment