0

I try to send product payment data to google analytics from the server, in response I get a status of 200, but in google analytics itself neither in normal events nor in debug view, I don't see my event, what am I doing wrong?

code:

const axios = require('axios')

const main = async () => {
    const payload = {
        client_id: 'xxxxxxxxxx.yyyyyyyyyy', // here my real client_id from cookies
        events: [
            {
                name: 'test_payment_purchase',
                params: {
                    debug_mode: 1,
                    currency: 'USD', 
                    value: 30,
                    engagement_time_msec: '100',
                    session_id: '123', //?
                    items: [
                        {
                            item_name: 'test_one',
                            item_id: '10',
                            item_category: 'RUBY',
                            item_variant: 'ruby',
                            quantity: 1,
                            price: 30,
                            item_brand: 'Brand'
                        }
                    ]
                }
            }
        ]
    }

    try {
        const url = `https://www.google-analytics.com/debug/mp/collect?measurement_id=${process.env.GA4_MEASUREMENT_ID}&api_secret=${process.env.GA4_API_SECRET}`
        const resp = await axios.post(url, payload)
        console.log(resp.status)
        console.log('Purchase event sent successfully in debug mode')
    } catch (error) {
        console.error('Error sending purchase event in debug mode:', error)
    }
}

main()

Every run, return status 200, but no data in GA tables

1
  • If i remove /debug/ from link: shell 204 Purchase event sent successfully in debug mode I get status 204((( Commented May 29 at 9:42

1 Answer 1

0

There are two endpoints for the measurement protocol

  • Measurement Protocol /mp/collect
  • Measurement Protocol Validation Server /debug/mp/collect

The first one sends hits to Google Analytics, The second validates hits

The debug endpoint is used to ensure that you have your request formatted correctly as the collection endpoint is fire and forget it will not do any validation and will always return a 200 even if the hit is incorrectly formatted.

The debug endpoint will not do anything but validate the hit it will not send the data to google analytics after validation.

Not the answer you're looking for? Browse other questions tagged or ask your own question.