Hi there,
I am trying to track clicks on some social sharing buttons I have.
I have the following code, but I don’t seem to be seeing any tracking info when it’s clicked:
<div data-network="twitter" class="st-custom-button st-btn-twitter" data-url="<?php the_job_permalink(); ?>" data-title="<?php wpjm_the_job_title(); ?>" onClick=”_gaq.push([‘_trackEvent’, ‘share’, ‘click’, ‘Twitter Share’, 5, true]);”><i class="fa fa-twitter"></i> Tweet</div>
Does the above code look ok?
I have tested it by clicking the button myself - would this still count as an event?
Thanks
Unless you have set up Analytics to ignore your own IP, it should track your activity. It will only work on the live site though.
Where you have these php functions in your data attributes, what do those functions do? I presume there is supposed to be an echo
within the actual functions, as you are not echoing there, just calling the functions.
Hi,
That’s strange. I will double check my code.
The PHP function fulls in some data from WordPress. This part works fine, it’s just the tracking code I’m having an issue with.
toolman:
”_gaq.push([‘_trackEvent’, ‘share’, ‘click’, ‘Twitter Share’, 5, true]);”
Is this supposed to have “curly” quotes?
I’ve just tried it with curly braces, but still nothing seems to show in Analytics.
I meant the quotes.
Using "
instead of ”
and '
instead of ‘
and ’
.
I’ve tried that and also with curly braces, but it still not tracking.
This is the code I have now:
<div data-network="facebook" class="st-custom-button st-btn-facebook" data-url="<?php the_job_permalink(); ?>" data-title="<?php wpjm_the_job_title(); ?>" onClick="_gaq.push(['_trackEvent', 'share', 'click', 'Facebook Share', 5, true]);" ><i class="fa fa-facebook-f"></i>Share</div>
Rather than posting the source code that has unfamiliar third party function calls in it, please post the HTML code that the browser would get.
1 Like
Sure, this is what is outputted:
<div data-network="facebook" class="st-custom-button st-btn-facebook" data-url="https://www.mywebsite.co.uk" data-title="Title of the page" onclick="_gaq.push(['_trackEvent', 'share', 'click', 'Facebook Share', 5, true]);"><i class="fa fa-facebook-f" aria-hidden="true"></i> Share</div>
Thanks. It looks like the PHP is OK. That leaves
_gaq.push(
['_trackEvent'
, 'share'
, 'click'
, 'Facebook Share'
, 5
, true]
);
Are you sure these are the correct parameters in the correct order?
Where did you find that? It doesn’t look like what I could find
rpkamp
June 9, 2018, 7:03pm
11
_gaq.push
is from the old Google analytics API. How you do this in the current API is described here: https://developers.google.com/analytics/devguides/collection/analyticsjs/events
2 Likes
SamA74
June 9, 2018, 7:03pm
12
That link says it’s a legacy library and recommends using the latest library.
1 Like
Thanks for the replies and the advice.
I’ve now tried using:
<div data-network="facebook" class="st-custom-button st-btn-facebook" data-url="https://www.mywebsite.co.uk" data-title="Title" ga('send', 'event', 'Videos', 'play', 'Fall Campaign', {nonInteraction: true});><i class="fa fa-facebook-f"></i> Share</div>
But still nothing is appearing in my Analytics
rpkamp
June 9, 2018, 7:37pm
14
Where did the onclick="...."
bit go?
Sorry, my bad.
I have added it, but still nothing showing.
<div data-network="facebook" class="st-custom-button st-btn-facebook" data-url="https://www.mywebsite.co.uk" data-title="Title" onclick="ga('send', 'event', 'Videos', 'play', 'Fall Campaign', {nonInteraction: true});"><i class="fa fa-facebook-f"></i> Share</div>
rpkamp
June 9, 2018, 7:47pm
16
Any errors on the console?
(in most browsers you can press F12 or ctrl+shift+i to open this)
Nope, not getting any errors
rpkamp
June 9, 2018, 7:52pm
18
And in the network tab, do you see it sending any data to Google?
This is what I have in the network tab:
rpkamp
June 9, 2018, 8:28pm
20
Doesn’t seem like a request was made.
Is there somewhere we can see this live?