Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to import Facebook Pixel on NuxtJs [closed]

I need to import the Facebook Pixel code in NuxtJs.

like image 496
Prapon Chaimuttayompol Avatar asked Jan 05 '23 02:01

Prapon Chaimuttayompol


1 Answers

You can create a file in the static repository : pixel.js, with the content given by facebook :

!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', 'XXYOUR CODEXX')
    fbq('track', 'PageView')

(I do not use the noscript tag with Nuxt fully based on javascrip)

Then on nuxt.conf.js file, add the lines :

script:[      
            {src:'pixel.js', type: 'text/javascript'}
        ]
like image 74
Matthieu Avatar answered Jan 12 '23 01:01

Matthieu