wemake-services / vue-analytics-facebook-pixel

A small wrapper around Facebook Pixel API
MIT License
24 stars 19 forks source link

init method is not working #5

Open Vishanth opened 5 years ago

Vishanth commented 5 years ago

I tried the following

from the main:

from the vue page:

But adding the script from Facebook Pixel initializes properly. What's the right way of initializing through the analytics.fbq.init() method?

Cheers!

sobolevn commented 5 years ago

What do you mean by not working? Exception? No data collected?

Vishanth commented 5 years ago

@sobolevn

I used fbq.init() method giving my app id but the event is not firing to the Facebook pixel (no data collected). However, it works if I use the Facebook pixel's code under <script> tag in index.html.

Not sure if I have missed something there or I may not be calling the Vue.analytics.fbq.init('AppID'); correctly.

sobolevn commented 5 years ago

See https://github.com/wemake-services/vue-analytics-facebook-pixel/issues/4

aboutsam commented 4 years ago

same issue here

what i have done:

  1. Add npm package
  2. add snippet in my index.html
  3. create init()
  4. load in my component

my error msg:

[Vue warn]: Error in mounted hook: "TypeError: this.$analytics.fbq is not a function"

pixel was find, but i cannot call from my component. did you have any advise?

srchulo commented 4 years ago

init also didn't work for me. I had to add the snippet from #4 , but I also had to init in my JS that I put in a <script> tag:

        !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', 'xxxxxxxx');

After that, passing in the router tracked each page view:

Vue.use(VueFacebookPixel, { router, debug: true })

hanenouche commented 4 years ago

same issue

Please @srchulo can you explain more about how we can use facebook pixel in a vue project, so what I did , is adding the script from #4 to my head tag in index.html file, after that I added VueFacebookPixel into my main.js but with the Facebook pixel helper extension, no pixel is added to my vuejs project

srchulo commented 4 years ago

@hanenouche I just put the code from my comment above in my script tag in head, and then did this:

Vue.use(VueFacebookPixel, { router })

And make sure to replace

fbq('init', 'xxxxxxxx');

With your own ID.