diego
diego

Reputation: 155

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

Upvotes: 5

Views: 9480

Answers (2)

mayrop
mayrop

Reputation: 701

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.

Upvotes: 9

Malte Ubl
Malte Ubl

Reputation: 850

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.

Upvotes: 10

Related Questions