Facebook Pixel event firing on button / link click

Hi. I’m trying to install my Facebook pixel on my website. The base code has been installed, as well as the code for standard events which fire upon page load - no problem there, the Tracking and Analytics part is pretty handy in this regard.

But when I try to place code for a custom event to fire when there is a link click or button click, it simply doesn’t work.

Am I doing it wrong? I was simply placing this snippet of code in the Add Custom Code section of Tracking and Analytics , in the header section.
Watch Now

This is as per Facebook’s instructions.

What I’d like to know is :

  1. This is supposed to be placed next to the code for the element (button in this case). How do I find where the code for the button is?
  2. Is there a simpler way to do this, and I’m just missing it? (I’m not a techie :0))

Any help in this matter would be greatly appreciated. Thanks so much!

Naresh

you have to use Wix Code and wixWindow.trackEvent. You can read more at https://www.wix.com/code/home/forum/product-updates/send-events-to-3rd-party-analytics-apps

Thanks, Andreas.
However, not being a techie, I was really hoping for step-by-step instructions on this somewhere.
This article is also a bit confusing, in that Facebook tracking code syntax is fbq(‘track’, ‘purchase’) or whatever event. Whereas here the format is wixWindow.track.event (‘purchase’). Will this cause the FB pixel to fire?
Also, which among the events given there would I have to pick for button click or link click tracking?

import wixWindow from 'wix-window'; 
//...  
wixWindow.trackEvent("purchase", {       
contents: [{         
sku: "P12345",         
name: "Really Fast Running Shoes",         
category: "Apparel/Shoes",         
price: 100,         
currency: "USD",         
brand: "Nike",         
variant: "Black",         
list: "Search Results",         
position: 1 }] 
});

Have you tried that? I dont know which contents you can send to Facebook Pixel.

Hi Andreas,

Tried your suggestion …it worked!
Thanks a lot :0).

I wonder if you could help me one more time.

I have many buttons / images / text links on one page, all leading to Amazon. I’d like to track any click on any of these with the same custom event “ClickAmzn”.

Using your method above, I can do it by adding a separate bit of code for every individual element on the page.

But what I’d like to know is…is there a single piece of code that I can install so that if someone clicks any button, or image, or link, the event gets triggered?

In other words, is there like a global onClick function or something, that can do this?

Based on what little I could understand of some reading that I did, I tried this :

$w.onReady(function () {
//TODO: write your page related code here…
const elements = (“image”, “Text”);
});

import wixWindow from ‘wix-window’;

export function Image_click () {
//Add your code for this event here:
wixWindow.trackEvent(“CustomEvent”, {
event: “Test2”,

} );
}

  1. It didn’t work, and
  2. I got an error message at the const line, saying ‘elements’ is unread.

Can’t understand any of this…could you help me , please?

Thank you so much!

Naresh

You could do a function like

function handleEvent(eventText) {
  wixWindow.trackEvent("CustomEvent", {
    event: eventText,
}

and then on all elements just add the call to the function

export function Image_click () {
  handleEvent("image click");
}

That way you only make one function that all elements call.

So sorry, not a techie :smiling_face:. Do i understand you correctly that

  1. EventText is to be replaced by actual event name i.e. ClickAmzn in this case?

  2. I will anyway have to write a function for every element individually?

Thanks so much.

Naresh

Hey
Just add the handleEvent function to your page and then on every button / image / element that has the click event call that function and replace eventText with the event you want to send. So just add the function once and call that function as in my sample above on every click event.

Hey Andreas,

Thanks so much - you’re the man! :0). This time too it worked. You just saved me $40 on Fiverr, trying to fix this issue.

Can I trouble you with one last issue, please?
I have html iframes on a page (which are basically images of products sold on Amazon - html code provided by Amazon). When I use the HTML iframe, the image is clickable, goes straight to teh page on Amazon.

But when I try to track this event, there is no click event handler for iframes.

How do I ensure that when I click on the image, it goes to Amazon as designed, but also that the click is reported using the function you had mentioned before?

Sorry to keep bothering you - but you’ve become my go - to man for issues like this :0).

Thanks so much,
Naresh