5

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

diego
  • 155
  • 2
  • 8

2 Answers2

10

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.

Malte Ubl
  • 851
  • 6
  • 9
9

It seems support was added on June 6, 2017. You can do:

<!-- Facebook Pixel Analytics tracking -->
<amp-analytics type="facebookpixel" id="facebook-pixel">
    <script type="application/json">
    {
        "vars": {
            "pixelId": "YOUR_ID"
        },
        "triggers": {
            "trackPageview": {
                "on": "visible",
                "request": "pageview"
            }
        }
    }
    </script>
</amp-analytics>
<!-- End Facebook Pixel Analytics example -->

The documentation can be found here.

mayrop
  • 681
  • 9
  • 19