Skip to content

Instantly share code, notes, and snippets.

@Mika-
Created October 18, 2015 10:34
Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save Mika-/90336cc3780c2a891da7 to your computer and use it in GitHub Desktop.
Save Mika-/90336cc3780c2a891da7 to your computer and use it in GitHub Desktop.
Use Google Analytics in AMP HTML
<amp-pixel src="https://ssl.google-analytics.com/collect?v=1&amp;tid=UA-12345678-1&amp;t=pageview&amp;cid=$RANDOM&amp;dt=$TITLE&amp;dl=$CANONICAL_URL&amp;z=$RANDOM"></amp-pixel>
/*
* Required parameters:
* v = API version number (currently 1)
* tid = Google Analytics property identifier (UA-12345678-1)
* t = hit type
* cid = client id (you should implement this via cookie etc.)
* z = random string to bypass caching (amphtml generates this to $RANDOM variable)
*
* Some nice to have parameters:
* dt = document title ($TITLE)
* dl = document location ($CANONICAL_URL)
*
* References:
* https://github.com/ampproject/amphtml/blob/master/builtins/amp-pixel.md
* https://developers.google.com/analytics/devguides/collection/protocol/v1/reference
*/
@MarkEdmondson1234
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment