What gets shared
Say thanks after a share
onShare runs the moment the share window is open. It cannot change anything and nothing waits for it — it is there so you can show a note, unlock a download, or file the press in analytics of your own.
The code
<div class="ats_kit ats_kit_size_32"> <a class="ats_btn_facebook"></a> <a class="ats_btn_x"></a> <a class="ats_btn_whatsapp"></a> <a class="ats_btn_copy"></a> <a class="ats_dd"></a> </div> <p id="ats-demo-status" role="status" aria-live="polite">Try Copy link to see the thank-you message.</p>
What to watch for
The event fires when the window opens, not when the reader actually posts. No widget can know the latter.
What the hook is given
The same object onBeforeShare was handed, with whatever that hook left in it: the service key, the address that went out and the title that went with it. A hook that throws is caught and the share carries on, because your code sits on our critical path and must not be able to break a button.
window.ats_config = {
onShare: function (s) {
showThanks(s.service); // 'whatsapp'
myLog('share', s.url);
}
};It fires when the window opens, not when the reader posts
What happens inside that window belongs to another site, and nothing on your page can see it. The reader may post, may edit for a minute and give up, may close the tab. Treat the event as "they set out to share" and the thank-you you write will be true; treat it as "they shared" and it will be wrong a fair slice of the time. With a shortener configured it fires earlier still — the window is open, the short link has not resolved yet.
A blocked popup fires nothing
If the window never opened, onShare does not run: a thank-you panel over a share that did not happen reads as a lie. Copy link, Print and a mailto: link do fire it, because each of those completed. A share cancelled from onBeforeShare fires nothing either.
Live demo
Copy link shows a thank-you message without opening another window. Other services report that the share window opened, not that a post was published.
Services (4 selected)
No service matches “”.
Button size
Shape
Circle is available when service names are off.
Behaviour
<div class="ats_kit ats_kit_size_32">
<a class="ats_btn_facebook"></a>
<a class="ats_btn_x"></a>
<a class="ats_btn_whatsapp"></a>
<a class="ats_btn_copy"></a>
<a class="ats_dd"></a>
</div>
<p id="ats-demo-status" role="status" aria-live="polite">Try Copy link to see the thank-you message.</p>
<script>
window.ats_config = window.ats_config || {};
window.ats_config.onShare = function (share) {
document.getElementById('ats-demo-status').textContent =
'Thanks for sharing with ' + share.service + '!';
};
</script>
<script async src="//static.addtosite.com/widget.js"></script>Related
More in What gets shared