I’m experiencing a 400 Bad Request error while implementing server-side GTM using the stape-sgtm-nodejs library, even though the server configuration appears to be correct.
Current Setup
I’ve followed the implementation example from the repository:
const sgtm = new StapeSGTM({
gtm_server_domain: 'https://server.example.com', // Tagging Server URL
request_path: '/data',
})
The server-side GTM container is properly configured and collecting data - I can confirm this through the Stape logs where I see GA4 events being tracked.
Implementation Details
Here’s my current implementation:
async sendConversion(request, profile) {
const eventData = {
client_id: 'xx1736510679', // sample
currency: 'JPY',
ip_override: request.ip || request.connection.remoteAddress || request.headers['x-forwarded-for']?.split(',')[0],
language: request.headers['accept-language']?.split(',')[0] || 'ja',
page_encoding: 'UTF-8',
user_data: {
sha256_email_address: transformations.sha256hex("test@example.com"),
},
}
sgtm
.sendEventData('page_view', eventData)
.then((result) => console.log('result:', result))
.catch((error) => console.log('error:', error))
}
Error Message
When trying to send events, I consistently receive this error:
error: Error: Something went wrong while sending the event.
{
details: { status: 400, statusText: 'Bad Request', error: '' }
}
What I’ve Verified
- The GTM server domain is correct and accessible
- The server-side GTM container is properly configured and collecting data
- The implementation follows the example from the stape-sgtm-nodejs repository
Has anyone encountered similar issues or can suggest what might be causing this 400 Bad Request error despite the server-side GTM appearing to work correctly?