1

I am trying to import the Meta (Facebook) pixel into my nuxtjs application, but am not having any success with other import methods. I have tried the methods suggested in How to import facebook pixel on nuxtjs, but they don't appear to work. Below is my code for that.

nuxt.config.js

head: {
  script: [
    { src:'pixel.js', type: 'text/javascript' }
  ]
}

pixel.js

!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', 'Insert pixel id here');
fbq('track', 'PageView');

I have also tried using nuxt-facebook-pixel-module, and that doesn't appear to work either. Here is how I am attempting to import that

nuxt.config.js

modules: [
  'nuxt-facebook-pixel-module'
],
facebook: {
  pixelId: 'Insert pixel id here',
  autoPageView: true,
}

I don't see any activity in my Facebook events manager and using the Facebook Pixel Helper extension for chrome I also can't detect a pixel.

If you have any advice on getting this working it would be appreciated. Thanks!

Digglit
  • 576
  • 1
  • 4
  • 11

1 Answers1

0

create app.html in root folder and write this.

<!DOCTYPE html>
<html {{ HTML_ATTRS }}>
<head {{ HEAD_ATTRS }}>
    {{ HEAD }}
    <!-- 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%27');
        fbq('init', 'yourid');
        fbq('track', 'PageView');
    </script>
    <noscript><img height="1" width="1" style="display:none"
                   src="https://www.facebook.com/tr?id=yourid&ev=PageView&noscript=1"
    /></noscript>
    <!-- End Meta Pixel Code -->
</head>
<body {{ BODY_ATTRS }}>
{{ APP }}
</body>
</html>
Hasan
  • 1