简体   繁体   中英

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

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?

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!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM