Best way to track social shares and events

Hi all,

You’ll be glad to know this isn’t a bug report or probem with 1.11.1 :slight_smile: All running great, and loving Piwik!

I want to start tracking social shares and clicks on mailto links, but I’m getting more and more confused - if I understand, I can do this with either event tracking or custom segments?

From my reading I understand the technical side, I think. I just want to be able to track the number of shares by page, as well as over time (so row evolution, and maybe transitions), so I can stop using the Addthis analytics, which are not that reliable, and not open of course.

Which is the ‘correct’ way to do this? How will the data show up on the dashboard? Will it impact the accuracy of my page views and bounce rates?

Thanks for any help, much appreciated, and fantastic project you’ve all developed here,

You can track with custom variables, with “onclick” call. The issue might be extra track pageviews, and impacts on bounce rate. You will have to test of course, but here is some basic code I used for Sharethis in the past that might help/inspire you

<script type="text/javascript">var switchTo5x=false;</script>
<script type="text/javascript" src=""></script>
<script type="text/javascript">stLight.options({publisher: "xxxxxxxxxxxxxxxxxxxxxxxx"}); </script>

<span class="st_twitter_large" displayText="Tweet" onclick="try {piwikTracker.setCustomVariable (1, 'Social Media Share', 'Tweet', 'page');piwikTracker.trackPageView();} catch(e) {};" target="_blank"></span>
<span class="st_facebook_large" displayText="Facebook" onclick="try {piwikTracker.setCustomVariable (2, 'Social Media Share', 'Facebook', 'page');piwikTracker.trackPageView();} catch(e) {};" target="_blank"></span>
<span class="st_linkedin_large" displayText="LinkedIn" onclick="try {piwikTracker.setCustomVariable (3, 'Social Media Share', 'LinkedIn', 'page');piwikTracker.trackPageView();} catch(e) {};" target="_blank"></span>

Hi Adrian,
Thanks for the reply. So if I understand correctly, it’s only possible with custom variables, as event tracking doesn’t really exist?
It sounds a bit hack-ish.
I found a good guide here: but does anyone know how the data is presented in the dashboard? Am I going to get useable data to slice and dice by page and time?
Thanks for any help

I’ve been ripping what’s left of my hair out trying to figure out why this is not working - I’m using as a reference.
For example, in the contact form submit button I have this code:

<input type="submit" name="submit" value="Send" class="newform_submit" onclick="javascript:piwikTracker.setCustomVariable(2,'Product Pricing','ViewProduct Price','page');piwikTracker.trackLink();"/>

But the custom variables is still ‘There is no data for this report’ and nothing shows up in the visitor log. What am I doing wrong?
I’m using the asnyc code, if that helps any.
The FAQs here seem to focus on setting custom variables in the tracker code for logging in etc. and don’t give any code examples in context, just lots of […] which don’t help much.
Thanks for any help or tips,

This code is for the SYNC version of the code. see the updated official guide at:

Thanks Matt, you’re a star.

I’ve figured out what all those […] mean and how they fit into the code. For the reference of others, what I have is:

onclick="javascript:_paq.push(['setCustomVariable',1,'Contact','Email link click','visit']);_paq.push(['trackPageView']);"

This is when the scope is visit, and all working no problem. However, when I change the scope to page it’s not working. There is no note in the tooltip and nothing shows up in the custom variables table. Is there anything missing from this code?

onclick="javascript:_paq.push(['setCustomVariable',2,'Engage','Print page','page']);_paq.push(['trackPageView']);"

Thanks again,


try replace the ; by && between the two function calls?

Hi Matt - I tried out your suggestion but it didn’t help I’m afraid.

I’ve been playing around the code all day and I think I’ve found the problem - there’s a conflict with the Addthis widget.

Addthis uses a class (eg addthis_button_print) to create a link, and it seems that this strips any onclick actions. It’s ironic because the reason I want to implement custom segments is to be able to stop using the dodgy Addthis analytics! But I can’t, at least not without removing addthis completely or just not tracking their functionalities.

FYI the code I posted above works on any other links, both with the scope set to visit and page, just don’t use it on any Addthis links or features :frowning:

AddThis is dodgy, and I would recommend not using this service if you can :slight_smile:

I agree, but I haven’t found a decent alternative, not even paid, let along open source! I just need them for the ‘other’ social networks (dozens of sharing links I’m not interested in keeping track of) as well as the spam-proof ‘tell a friend’ and ‘add to favourites’ links.
If anybody knows of any good alternative (and no, not share this!) please let me know, thanks!

Hi Alex. Guess this is not relevant any more, however…

Reporting of Addthis seems completely inaccurate, possible even fraudulent. Following my own data, Addthis not only counts clicks on ‘social sharing services’ as share, but also clicks on ‘extend’ buttons. Due to my calculations, only about a third of all reported shares for our website are actual shares - the rest (about 66% of shares as reported by Addthis) are just interactions with the tool that did not result in shares.

What you might do: You can put UTM (order other syntax) strings behind your share links. Those you can use as measurement of ‘campaign’ or ‘source’. Now you can calculate the success of the channel, the specific link, the campaign, or combinations of those at entrances and conversion level. This will also give you a better view on the actual efficiency of your link / campaign (hard kpi) and not only on soft-kpi’s such as sharing.

3 posts were split to a new topic: Replace AddThis with Matomo