1

I just switched my site over to SSL and all of my social sharing button counts have reset to zero, which is expected, but apparently it's possible to tell those buttons to use the old http urls in order to bring back the old counts.

I just can't figure out how to do it for my setup, which is AddThis for the buttons and Php/Html for the code (Joomla actually, but that may be irrelevant).

The AddThis code is simple:

<div class="addthis_sharing_toolbox" data-url="THE URL"></div>

So my best guess is that I need to take the current URL, change it from https to http, and plug it into the above 'data-url'.

But looking at other threads here, there seems to be a lot of controversy about how to securely and correctly get the current URL, so that's where I'm getting stuck.

(And then on top of that, I'll need to make this switch only for past articles, not new ones, but that's another story.)

Any ideas?

Thanks very much, Phil

Daniel Widdis
  • 8,424
  • 13
  • 41
  • 63

4 Answers4

1

The share counts are based off of the exact URL and unfortunately, the APIs for each of the sharing services (Facebook, Pinterest, etc.) treat the protocols as distinct URLs.

The only thing you could do prevent losing the share counts from existing URLs would be to set override the shared URL to be the old HTTP URL. Then, you'd need to setup a 301 redirect on your site to redirect the visitor from the old URL to the new HTTPS URL after a visitor clicks the old URL from a shared link on Facebook (or any other service).

It looks like you already found the instructions for changing the URL that's shared (http://www.addthis.com/academy/setting-the-url-title-to-share/), so you would just set the data-url attribute to be the old (HTTP) URL.

Matt
  • 44
  • 2
  • Thanks Matt, seems like you restated pretty much what I had stated in my original question. I appreciate you taking the time. I eventually figured it out and posted an answer. Cheers. – philraymond Sep 13 '16 at 16:10
0

Took me all day, but I finally figured this out! This gave me a lot of the answer, but I still had trouble tweaking it for AddThis.

Here's the code (the first line applies the fix only to articles published before Aug 1, 2016, because I don't need to make the change for newer articles):

<?php if (strtotime($this->item->publish_up) < 1470009600) : ?>
<script type="text/javascript">
function buttons(){
var kCanonical = document.querySelector("link[rel='canonical']").href;
window.kCompositeSlug = kCanonical.replace('https://','http://');
return;
}
buttons();
var addthis_share = { url: ''+kCompositeSlug+'' };
</script>
<?php endif; ?>
<script type="text/javascript" src="//s7.addthis.com/js/300/addthis_widget.js#pubid=ID-GOES-HERE" async="async"></script>
0

Here is my code that worked on a client's Joomla / K2 site, this is part of my item template override:

<?php if (strtotime($this->item->publish_up) < 1503201600) : ?>
    <!-- Non SSL Command for buttons here -->
    <div class='shareaholic-canvas' data-app='share_buttons' data-app-id='YOURAPPIDHERE' data-link='http://www.yoursite.com<?php echo $this->item->link; ?>'></div>
<?php else: ?>
    <!-- Regular SSL Command for buttons here -->
    <div class='shareaholic-canvas' data-app='share_buttons' data-app-id='YOURAPPIDHERE'></div>
<?php endif; ?>

Details / analysis of solution here: https://www.covingtoncreations.com/blog/solution-for-lost-share-count-after-moving-to-ssl-https

Rob
  • 26,989
  • 16
  • 82
  • 98
nate covington
  • 67
  • 1
  • 1
  • 6
0

Does it work on a Joomla website which uses Sharethis not AddThis ? Currently I have the following code in the

<script type="text/javascript">var switchTo5x=true;</script>
<script type="text/javascript" src="https://ws.sharethis.com/button/buttons.js"></script>
<script type="text/javascript">stLight.options({publisher: "XXXXXXXXXXXX", doNotHash: false, doNotCopy: false, hashAddressBar: false});</script>
<meta property="fb:app_id" content="XXXXXXXXXXXX"/>
<div id="fb-root"></div>
<script>(function(d, s, id) {
  var js, fjs = d.getElementsByTagName(s)[0];
  if (d.getElementById(id)) return;
  js = d.createElement(s); js.id = id;
  js.src = "//connect.facebook.net/en_US/sdk.js#xfbml=1&appId=XXXXXXXXXXXX=v2.0";
  fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>
9944990
  • 444
  • 1
  • 5
  • 16