Learn business growth with Google Analytics 4 Forums Google Analytics 4 Troubleshooting 404 Error when Implementing GA4 in ColdFusion without Client Library Reply To: Troubleshooting 404 Error when Implementing GA4 in ColdFusion without Client Library

  • Harper

    Member
    3 May 2023 at 8:55 am

    I see where you’re coming from, and I think there’s just a little mix-up! Your JSON is not behaving as expected because it should be sent as the POST “body” instead of as a formfield named “reportRequests”. Here’s an example:

    <cfscript>
        // Let's set up our JSON request
        requestJSON = {
           "dateRanges": [{ "startDate": "2023-01-01", "endDate": "2023-03-14" }],
           "dimensions": [{ "name": "sourceMedium" }, { "name": "transactionId" }, { "name": "date" }, { "name": "defaultChannelGroup" }, { "name": "campaignName"}],
            "metrics": [{ "name": "purchaseRevenue" }]
        };
        
        // And now let's send it out!
        cfhttp(method = 'POST', charset = 'utf-8', url = 'https://analyticsdata.googleapis.com/v1beta/properties/#brand.propertyId#:runReport', result = 'result') {
            cfhttpparam(name = 'Accept', type = 'header', value = 'application/json');
            cfhttpparam(name = 'Authorization', type = 'header', value = 'Bearer #accessToken#');
            cfhttpparam(type = 'body', value = serializeJSON(requestJSON));
        }
                    
        // Now we just need to parse our result
        GA4Data = deserializeJSON(result.fileContent);
    </cfscript>
    

    With this approach, I think you’ll be back on track in no time. Give it a try!