问题
According to Facebook's documentation for the Share Dialog, you can use Javascript to trigger open a share dialog so that the user can share whatever URL you pass in:
FB.ui({
method: 'share',
href: 'https://developers.facebook.com/docs?myTrackingParam=topShareButton',
}, function(response){});
However, if you want to do any referral tracking by appending a query string to the href
property gets stripped, since the FB uses the og:url
meta tag when it crawls the URL. I use the query params to track which share buttons are causing the most traffic. So my question: how can you do clickthrough tracking via the FB Share Dialog? Is there a way to set some query string value in the URL when sharing?
回答1:
After some experimentation and piecing together separate FB docs, you can indeed set whatever value that gets passed back in the fb_ref query param. However, this requires us to turn the share into an Open Graph call.
So instead of using the share
method, we could use the share_open_graph method. Thus, we can set the action_properties
, which would include the ref
property:
FB.ui({
method: 'share_open_graph',
action_type: 'og.shares',
action_properties: JSON.stringify({
object:'https://developers.facebook.com/docs',
ref: 'topShareButton'
})
}, function(response){});
Thus, the link that is shown on the Newsfeed/Timeline will be https://developers.facebook.com/docs?fb_ref=topShareButton
. And now you can do whatever tracking your heart desires!
来源:https://stackoverflow.com/questions/27163195/how-do-you-do-clickthrough-tracking-via-the-fb-share-dialog