Amp analytics encodeURIComponent for tracking pixel

91 Views Asked by At

I have an amp page that I would like to track with our analytics tool.

The non amp implementation for the tracking pixel is something like this e.g.

var payload = {a:1,b2}
var img = document.createElement("img");

img.src = "http://www.examplepixel.com?data=" + encodeURIComponent(payload)

I have read the documentation on amp-pixel and amp-analytics I see no way to perform the encoding.

How can I do this?

1

There are 1 best solutions below

2
Sebastian Benz On

The amp way is using amp-pixel:

<amp-pixel src="http://www.examplepixel.com?data=%7Ba%3A1%2Cb%3A%202%7D"
layout="nodisplay"></amp-pixel>