N
Nuxt2y ago
glikli

Implement Facebook Pixel

What is the recommended way to implement a facebook pixel? I have to add script tags with custom js before </head> tag
4 Replies
glikli
glikliOP2y ago
Anyone?
Thomas Bnt
Thomas Bnt2y ago
Hello @glikli, you can get your script in your nuxt.config file :
export default defineNuxtConfig({
app: {
head: {
charset: 'utf-8',
viewport: 'width=device-width, initial-scale=1',
},
script: [
{
src: "https://example.com/embed.js",
async: true
},
]
}
})
export default defineNuxtConfig({
app: {
head: {
charset: 'utf-8',
viewport: 'width=device-width, initial-scale=1',
},
script: [
{
src: "https://example.com/embed.js",
async: true
},
]
}
})
glikli
glikliOP2y ago
Hi @Thomas Bnt, thanks for answering. The problem is that it is a whole code snippet I need to implement:
<!-- Meta 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’, ‘{{ facebookPixelId }}’);
fbq(‘track’, ‘PageView’);
</script>
<noscript><img height=“1” width=“1" style=“display:none”
src=“https://www.facebook.com/tr?id={{facebookPixelId}}&ev=PageView&noscript=1”
/></noscript>
<!-- End Meta Pixel Code -->
<!-- Meta 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’, ‘{{ facebookPixelId }}’);
fbq(‘track’, ‘PageView’);
</script>
<noscript><img height=“1” width=“1" style=“display:none”
src=“https://www.facebook.com/tr?id={{facebookPixelId}}&ev=PageView&noscript=1”
/></noscript>
<!-- End Meta Pixel Code -->
I've now created a plugin and implemented it that way. Just wondering if there is an easier way to implement this..
Thomas Bnt
Thomas Bnt2y ago
Or you can import a script JS file, and put your code directly
Want results from more Discord servers?
Add your server