How do you do clickthrough tracking via the FB Share Dialog?

夙愿已清 提交于 2019-12-13 01:29:17

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!