Welcome to Didiads AMP Test Page (Didiads-qwer1234)
What's not working?
1. Following Facebook pixel code will not work as AMP does not allow any sync script
inside
body
, even in noscript
form.
<!-- Facebook Pixel Code -->
<script>
!function(f,b,e,v,n,t,s){if(f.fbq)return;n=f.fbq=function(){n.callMethod?
n.callMethod.apply(n,arguments):n.queue.push(arguments)};if(!f._fbq)f._fbq=n;
n.push=n;n.loaded=!0;n.version='2.0';n.queue=[];t=b.createElement(e);t.async=!0;
t.src=v;s=b.getElementsByTagName(e)[0];s.parentNode.insertBefore(t,s)}(window,
document,'script','https://connect.facebook.net/en_US/fbevents.js');
fbq('init', '1388136481514478'); // Insert your pixel ID here.
fbq('track', 'PageView');
</script>
<noscript><img height="1" width="1" style="display:none"
src="https://www.facebook.com/tr?id=1388136481514478&ev=PageView&noscript=1"
/></noscript>
2. Following static pixel will not work too, as AMP replaced img
with amp-img
.
<img height="1" width="1" style="display:none" src="https://www.facebook.com/tr?id=1388136481514478&ev=PageView&noscript=1"/>
What's working?
1. Static pixel in amp-img
form. But you can not use display: none;
to hide it as AMP
will not even load it. Instead, you can make it transparent so user will not see it.
<style>
.hidden {
border: none;
opacity: 0;
}
</style>
<amp-img class="hidden" height="1" width="1" src="https://www.facebook.com/tr?id=1388136481514478&ev=PageView"/>
2. We can use amp-analytics
as described
here.
You need to load amp-analytics
in your page, and configure corrrectly.
<!-- place below line in header -->
<script async custom-element="amp-analytics" src="https://cdn.ampproject.org/v0/amp-analytics-0.1.js"></script>
<!-- place below section in body -->
<amp-analytics>
<script type="application/json">
{
"transport": {"xhrpost": false, "beacon": true},
"requests": {
"base": "https://www.facebook.com/tr",
"pageView": "${base}?id=${pixelid}&ev=PageView"
},
"vars": {
"pixelid": 1388136481514478
},
"triggers": {
"pageLoad": {
"on": "visible",
"request": "pageView"
}
}
}
</script>
</amp-analytics>
With this technique you can bind events as normal javascript code. See official doc here.
© 2017, Yu LI
Validate this page