Using amp-analytics - no vendor : get http error 404 when try to send data to my page

176 Views Asked by At

I am trying to implement amp-analytics - no vendor for Google AMP pages, for the pageview. I send the metrics to a page using URL parameters to define what I want to track, and this URL works with no problem:

https://tru.am/page_views?clientID=1182&version=13&canonical=https%3A%2F%2Fs3.amazonaws.com%2Ftru-am-dev%2Fpromote%2Ftest.amp.6.analytics.html&ogURL=https%3A%2F%2Fs3.amazonaws.com%2Ftru-am-dev%2Fpromote%2Ftest.amp.6.analytics.html&referrer=TBA&title=test%20page%20for%20AMP%20analytics&image=http%3A%2F%2Fwww.trueanthem.com%2Fwp-content%2Fuploads%2F2016%2F03%2Fabout_bottom.jpg&callback=eqwest_1502748414821

I get a response that states the data was collected.

Now, when I implement it in a Google AMP page I get an error code 404 triggered by the Google transport.js library, line 84 when it makes teh call to my URL and sends the parameters to collect the the data.

transport.js: line with the issue is:

const result = win.navigator.sendBeacon(request, '');

This is the context from transport.js:

...
/**
       * @param {!Window} win
       * @param {string} request
       * @return {boolean} True if this browser supports navigator.sendBeacon.
       */
      static sendRequestUsingBeacon(win, request) {
        if (!win.navigator.sendBeacon) {
          return false;
        }
        const result = win.navigator.sendBeacon(request, '');
        if (result) {
          dev().fine(TAG_, 'Sent beacon request', request);
        }
        return result;
      }
...

Teh analytics code I am using is this in the AMP page:

<amp-analytics>
      <script type="application/json">
      {
        "requests": {
          "pageview": "https://tru.am/page_views?clientID=${clientId}&version=${version}&canonical=${canonical}&ogURL=${ogURL}&referrer=${referrer}&title=${title}&image=${image}&callback=${callback}"
        },
        "triggers": {
          "trackPageview": {
            "on": "visible",
            "request": "pageview",
            "vars": {
              "eventId": "pageview",
              "clientId": "1182",
              "version" : "13",
              "canonical": "https://s3.amazonaws.com/tru-am-dev/promote/test.amp.6.analytics.html",
              "ogURL": "https://s3.amazonaws.com/tru-am-dev/promote/test.amp.6.analytics.html",
              "referrer": "TBA",
              "title": "test page for AMP analytics",
              "image": "http://www.trueanthem.com/wp-content/uploads/2016/03/about_bottom.jpg",
              "callback": "eqwest_1502748414821"
            }
          }
        }
      }
      </script>
      </amp-analytics>

I get no other error code in the page, and using #development=1 in the URL I get the AMP validation successful message in the browser's console.

Details of the 404 error:

Request URL:https://tru.am/page_views?clientID=1182&version=13&canonical=https%3A%2F%2Fs3.amazonaws.com%2Ftru-am-dev%2Fpromote%2Ftest.amp.6.analytics.html&ogURL=https%3A%2F%2Fs3.amazonaws.com%2Ftru-am-dev%2Fpromote%2Ftest.amp.6.analytics.html&referrer=TBA&title=test%20page%20for%20AMP%20analytics&image=http%3A%2F%2Fwww.trueanthem.com%2Fwp-content%2Fuploads%2F2016%2F03%2Fabout_bottom.jpg&callback=eqwest_1502748414821
Request Method:POST
Status Code:404 
Remote Address:104.25.163.34:443
Referrer Policy:no-referrer-when-downgrade

Then why if very same URL works in the browser but fails (error code 404) in the Google transport.js library?

1

There are 1 best solutions below

0
On

The issue is that the page collecting the Analytics signal (//tru.am/page_views) does not accept POST requests, only GET requests. Google sends the data from as a POST, and then it generates the 404 error.