how to add Facebook's pixel into Google's AMP?

diego picture diego · Aug 2, 2017 · Viewed 7.3k times · Source

For the time being, it appears that no one at Facebook nor Google have added Facebook tracking pixel into amp-analytics yet.

Does anybody here knows how to do it ? sample code or github is preferred.

thank you very much

Answer

Malte Ubl picture Malte Ubl · Aug 2, 2017

This should work

<amp-pixel src="https://www.facebook.com/tr?id=YOUR_ID&ev=PageView&noscript=1" 
    layout="nodisplay"></amp-pixel>

You will need to change YOUR_ID to the ID you can find in Facebook's tracking code.

I created this by adopting the noscript src from their sample script for use in amp-pixel. More advanced usages would be possible, but ideally Facebook would provide the respective documentation.