Sharing Customization

Share Count Recovery

AddToAny share count recovery lets you combine share counts from two URLs. This is useful for recovering old share counts when transitioning from HTTP to HTTPS, or when changing domain names or URL structures.

Recover HTTP counts

Recover counts for the HTTP version of shared HTTPS URLs by setting the recover_protocol property.

In Drupal, add the following JavaScript code to your "Additional JavaScript" box in Configuration > Web services > AddToAny > Additional Options.

In WordPress, add the following JavaScript code to your "Additional JavaScript" box in Settings > AddToAny.

a2a_config.counts = { recover_protocol: 'http', };
<div class="a2a_kit a2a_kit_size_32 a2a_default_style" data-a2a-url="https://www.example.com/" data-a2a-title="Example Site">
    <a class="a2a_button_facebook a2a_counter"></a>
    <a class="a2a_button_pinterest a2a_counter"></a>
    <a class="a2a_button_tumblr a2a_counter"></a>
    <a class="a2a_button_reddit a2a_counter"></a>
    <a class="a2a_dd a2a_counter" href="https://www.addtoany.com/share"></a>
</div>

<script>
var a2a_config = a2a_config || {};
a2a_config.counts = { recover_protocol: 'http', };
</script>

<script async src="https://static.addtoany.com/menu/page.js"></script>

Recover a domain's counts

Recover counts from the old domain of shared URLs by setting the recover_domain property.

a2a_config.counts = { recover_domain: 'old.example.com', };
<script>
var a2a_config = a2a_config || {};
a2a_config.counts = { recover_domain: 'old.example.com', };
</script>

Recover any URL's counts

For recovery of an old URL structure, you can set the recover property to a function that returns the old URL. A data object is passed to the function, allowing you to recover the old URL based on the shared URL and other conditions.

Properties of the recover function's data object include:

  • url
    • The shared URL.
  • domain
    • The shared URL's domain.
  • protocol
    • The shared URL's protocol.
  • pathParts
    • An array of the shared URL's pathname parts.
  • kit
    • The .a2a_kit element that contains the share counter(s).

a2a_config.counts = {
    recover: function(data) {
        // Replace the shared URL's first occurrence of https://www.example.com/new/ with http://old.example.com/old/
        return data.url.replace('https://www.example.com/new/', 'http://old.example.com/old/');
    },
};
<script>
var a2a_config = a2a_config || {};
a2a_config.counts = {
    recover: function(data) {
        // Replace the shared URL's first occurrence of https://www.example.com/ with http://old.example.com/
        return data.url.replace('https://www.example.com/', 'http://old.example.com/');
    },
};
</script>
a2a_config.counts = {
    // Recover old Blogger domain
    recover_domain: 'blogger.blogspot.com',
    // And the old Blogger URL structure
    recover: function(data) {
        // Replace the shared URL's trailing / with .html
        return data.url.replace(/\/$/, '.html');
    },
};
a2a_config.counts = {
    // Recover old Blogger domain
    recover_domain: 'blogger.blogspot.com',
    // And the old Blogger URL structure
    recover: function(data) {
        // Append .html to the shared URL
        return data.url + '.html';
    },
};
<script>
var a2a_config = a2a_config || {};
a2a_config.counts = {
    // Recover old Blogger domain
    recover_domain: 'blogger.blogspot.com',
    // And the old Blogger URL structure
    recover: function(data) {
        // Replace the shared URL's trailing / with .html
        return data.url.replace(/\/$/, '.html');
    },
};
</script>
a2a_config.counts = {
    // Recover old URL structure
    recover: function(data) {
        var bodyData = document.body.dataset;
        // If the <body> tag has "data-" attributes in the HTML like:
        // <body data-year="2020" data-month="01" data-post-id="123">
        if (bodyData && bodyData.year && bodyData.month && bodyData.postId) {
            // Arrange the pathname parts of the old URL like:
            // http://old.example.com/2020/01/123/post-name/
            return 'http://old.example.com/' 
                + bodyData.year + '/' 
                + bodyData.month + '/' 
                + bodyData.postId + '/' 
                + data.pathParts[data.pathParts.length - 1] + '/';
        }
    },
};
<script>
var a2a_config = a2a_config || {};
a2a_config.counts = {
    // Recover old URL structure
    recover: function(data) {
        var kitData = data.kit.dataset;
        // If the AddToAny instance has "data-" attributes in the HTML like:
        // <div class="a2a_kit" data-year="2020" data-month="01" data-post-id="123">
        if (kitData && kitData.year && kitData.month && kitData.postId) {
            // Arrange the pathname parts of the old URL like:
            // http://old.example.com/2020/01/123/post-name/
            return 'http://old.example.com/' 
                + kitData.year + '/' 
                + kitData.month + '/' 
                + kitData.postId + '/' 
                + data.pathParts[data.pathParts.length - 1] + '/';
        }
    },
};
</script>