Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #1309235

    Hi,

    I use Enfold to built my website. I’m quiet happy but I need to track social media buttons on Google Analytics. I added some codes to functions.php but I need to change Social Media buttons to onclick link buttons.

    https://support.google.com/analytics/answer/1136920?hl=tr#zippy=%2Cbu-makalede-ele-al%C4%B1nan-konular
    Google says that in this article, link should be like this.

    ***a href=”http://www.example.com” onclick=”captureOutboundLink(‘http://www.example.com’); return false; ** example.com’a göz atın***

    As you can see regular code as below has no onclick codes. How can I change this. Urgent HELP.

    <li class=’social_bookmarks_whatsapp av-social-link-whatsapp social_icon_2′>
    ///a target=”_blank” href=’https://api.whatsapp.com/send?phone=90533*******&text=Merhaba%2C+size+siteniz+uzerinden+ulasiyorum.&#8217; title=’WhatsApp’ rel=”noopener”><span class=’avia_hidden_link_text’>WhatsApp</span> ///

    Best Cenk

    • This topic was modified 3 years, 4 months ago by cengolino.
    #1309622

    Hey cengolino,
    Thank you for your patience and for the link to your site and the code you wanted to add, I wrote this function that you can add to your functions.php but I would recommend using a Child Theme so that it won’t be lost in an update.

    function custom_captureOutboundLink() { ?>
        <script>
    (function($){
        var getinstagram = $(".main_menu .social_bookmarks_instagram a").attr("href");
        var getwhatsapp = $(".main_menu .social_bookmarks_whatsapp a").attr("href");
        var getfacebook = $(".main_menu .social_bookmarks_facebook a").attr("href");
        $(".main_menu .social_bookmarks_instagram a").attr("onclick", "captureOutboundLink("+ getinstagram +"); return false;");
        $(".main_menu .social_bookmarks_whatsapp a").attr("onclick", "captureOutboundLink("+ getwhatsapp +"); return false;");
        $(".main_menu .social_bookmarks_facebook a").attr("onclick", "captureOutboundLink("+ getfacebook +"); return false;");
    })(jQuery);
    </script>
        <?php
    }
    add_action('wp_footer', 'custom_captureOutboundLink');

    Best regards,
    Mike

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.