Twitter 的推文按钮有回调吗?
有没有办法在 Twitter 的 Tweet 按钮上注册回调?我希望能够跟踪我网站上的哪些特定用户在推特上发布了链接.我无法添加 onClick 事件,因为它是跨域 iFrame.还有其他想法吗?
Is there a way to register a callback on Twitter's Tweet button? I'd like to be able to track which particular users on my site have tweeted a link. I can't add on onClick event because it's a cross-domain iFrame. Any other ideas?
我见过一种方法,但似乎不可靠.他们的文档 没有提及任何内容,所以我正在寻求解决方法的帮助.>
I've seen one way to do it but it seems unreliable. Their documentation doesn't mention anything so I am looking for help with a work-around.
Twitter 有 Web Intent 事件 用于 loaded
、rendered
、resize
、tweet
、follow
、转发、喜欢
和点击
.
Twitter has Web Intent events for loaded
, rendered
, resize
, tweet
, follow
, retweet
, like
, and click
.
twttr.events.bind(
'tweet',
function (event) {
// Do something there
}
);
行为在秋季发生了变化2015 由于事件完成后发生的回调不可靠.
The behavior was changed in the fall of 2015 due to the unreliableness of callbacks happening after an event is complete.
它们现在将在用户调用您页面中的操作时触发,而不是在操作完成后触发.
They will now be triggered when a user invokes the action in your page, rather than after the action is completed.
<script>
// Performant asynchronous method of loading widgets.js
window.twttr = (function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0],
t = window.twttr || {};
if (d.getElementById(id)) return t;
js = d.createElement(s);
js.id = id;
js.src = "https://platform.twitter.com/widgets.js";
fjs.parentNode.insertBefore(js, fjs);
t._e = [];
t.ready = function(f) {
t._e.push(f);
};
return t;
}(document, "script", "twitter-wjs"));
</script>
<script>
// Wait until twttr to be ready before adding event listeners
twttr.ready(function (twttr) {
twttr.events.bind('tweet', function(event) {
console.log(event);
});
});
</script>