Search code examples
htmlgoogle-analyticsamp-htmlfacebook-pixelgoogle-amp

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


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


Solution

  • 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.