John Grischam
John Grischam

Reputation: 263

onclick event tracking not working

I have a share button and want to track onclick events. Button works properly but when i add onclick event it disappears completely.

Here is the script of my button with onclick included:

<script type='text/javascript'>
//<![CDATA[
var siteurl = window.location.href;
  document.write('<div class="sharesimp"><div class="sharede"> \
\
<a class="fb social-popup" href="https://www.facebook.com/sharer/sharer.php?u=' + siteurl + '" target="_blank" title="Share to Facebook" onclick="_gaq.push(['_trackSocial', 'Facebook', 'Share', 'pageURL']);">\
    <i class="fa fa-facebook fbtea"></i> Share Facebook</a> \
 \
</div><div class="clear"></div></div> \
');
//]]>
</script>

Upvotes: 2

Views: 154

Answers (1)

Asons
Asons

Reputation: 87191

The reason it fails is that you use single quotes ' to surround the whole string, so you need to escape the inner single quotes '

onclick="_gaq.push([\'_trackSocial\', \'Facebook\', \'Share\', \'pageURL\']);"

Upvotes: 3

Related Questions