Hi,
Have you added the facebook pixel script anywhere in the page? If you added it then you can use code like this.
<a href="http://somewhere.com" onclick="fbq('track', "MyCustomEvent");">here's a link to somewhere</a>
Thanks
Mohammad
@mdshak: “Have you added the facebook pixel script”
Oh sure you bet, it’s in the header.
When I insert your/my code in Text mode, shift to Visual then back, WordPress strips out the onclick code:
Pasted in Text mode:
<a href="http://somewhere.com" onclick="fbq('track', "MyCustomEvent");">here's a link to somewhere</a>
Shift to Visual and back to Text, and:
<a href="http://somewhere.com">here's a link to somewhere</a>
Wordpress has no problem with this in a page or post, by the way:
<script type="text/javascript">fbq('track', "MyCustomEvent"); </script>
When the page loads, the pixel fires. Dandy.
But it won’t let me use it with onclick.
Hi,
Please follow the given below steps.
1- Just add a class to links like this:-
here’s a link to somewhere
2- Now you can insert this Jquery/Javascript code to WordPress post/page.
<script type="text/javascript">
jQuery(document).ready(function($){
$("a.fbPixelTrack").click(function(){
fbq('track', "MyCustomEvent");
});
});
</script>
Thanks
Mohammad
Hi Mohammad, thanks.
Am I supposed to be seeing some code here?:
1- Just add a class to links like this:-
here’s a link to somewhere
Thank you,
Steve
Hi,
I mean to add a class for link. Just add a class to link like class=”fbPixelTrack”
< a href="your link" class="fbPixelTrack" > Link Text < /a>
Thanks
Mohammad
Thanks Mohammad. But unfortunately this is firing the pixel every time the page loads. AND each time the link is clicked.
Thanks,
Steve
Hi,
We near to fix it. Please provide me specific page url to debug it. I will give you definitely solid solution for it.
Thanks
Mohammad
Hmmm, I just have a private testing page set up within my WP. Nothing public to show.
Basic problem is MCE editor, doesn’t allow onclick, erases it.
Any other tricks very much welcome, and your continued attention very much appreciated.
Could put an if/then in the following code, saying “only execute on link click, not on page load”? Or some such?
<script type="text/javascript">
jQuery(document).ready(function($){
$("a.fbPixelTrack").click(function(){
fbq('track', "MyCustomEvent");
});
});
</script>
Thanks,
Steve
Oh and just to add, I test by looking at the Custom Conversion count (tracking “MyCustomEvent”) in a private Facebook Ad Manager account. I can’t share access to that account. Thx.
Hi,
I am afraid that its not possible to say anything without debug the site. I will wait for your live site.
Thanks
Mohammad
If I published the page you wouldn’t be able to see anything cause WordPress won’t publish it. Sorry, can’t give login access.
Moderator
Jan Dembowski
(@jdembowski)
Forum Moderator and Brute Squad
Sorry, can’t give login access.
*Reads whole topic*
Fortunately no one was asking for login access and you’re right to never permit anyone here to do that. 😉