• Hi all:

    I know this is widely covered, but:

    I just want the simplest possible method for an -a href- link to fire my Facebook pixel using ‘onclick’ (or ??).

    <a href="http://somewhere.com" onclick="fbq('track', "MyCustomEvent");">here's a link to somewhere</a>

    Or:

    <a href="http://somewhere.com" onclick="<script type="text/javascript">fbq('track', "MyTestEvent"); </script>");">here's a link to somewhere</a>

    Would prefer not to add a plugin. (And don’t want to enable javascript in pages/posts sitewide.)

    This is for a personal site using this in one place so don’t care about properly structured CSS/HTML conventions. Just simple and straightforward.

    Any suggestions much appreciated. Thanks all.

Viewing 13 replies - 1 through 13 (of 13 total)
  • 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

    Thread Starter worksitemassage

    (@worksitemassage)

    @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>

    Thread Starter worksitemassage

    (@worksitemassage)

    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

    Thread Starter worksitemassage

    (@worksitemassage)

    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

    Thread Starter worksitemassage

    (@worksitemassage)

    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

    Thread Starter worksitemassage

    (@worksitemassage)

    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

    Thread Starter worksitemassage

    (@worksitemassage)

    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

    Thread Starter worksitemassage

    (@worksitemassage)

    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. 😉

Viewing 13 replies - 1 through 13 (of 13 total)

The topic ‘Any very simple way to fire Facebook pixel from onclick?’ is closed to new replies.