2016年1月18日 星期一

Jetpack: add UTM monitoring to sharing buttons

After determining a pleasant little problem within the Jetpack help boards final week, I needed to share the outcomes with you.

To begin with, I have to thank Aquif Shaikh for his query in the original thread. This thread required a bit extra digging than ordinary, and I really like a very good problem.

The query was truly fairly easy: learn how to add UTM monitoring to the Jetpack sharing buttons. In case you’re not accustomed to UTM monitoring, you will need to verify this generator. UTM monitoring permits you to monitor particular URLs in Google Analytics.

Let’s get began.

Jetpack provides a sharing_permalink filter. It appeared straightforward so as to add parameters to the prevailing permalinks. It turned out to be a bit extra difficult than I assumed, due to 2 points:

  1. Twitter, Google+, and probably different Social Networks seem to strip actual GET parameters from URLs whenever you use their sharing instruments. To work round this, I made a decision to ship brief URLs as an alternative of the unique permalink and the UTM monitoring parameters. To do that, I used goo.gl. It is nonetheless considered one of my favourite URL shorteners (when you do not use your own, and Google gives a very good set of directions that will help you use their APIs. My colleague Konstantin additionally launched a Goo.gl plugin within the repo in the event you’re taken with implementing Goo.gl in your website.
  2. Google Analytics did not actually just like the encoded ampersands within the URLs I created, and did not monitor the campaigns correctly.

Right here is the ultimate, commented code. Depart a remark in case you have questions, or have a greater concept to unravel this challenge!

/**
* Overwrite the hyperlinks utilized in Jetpack's Sharing module.
*
* @see http://ift.tt/1OCE0Su
*
* @param string $url
* @param int $post_id
* @param int $sharing_id
* @filter sharing_permalink
* @return string
*/
perform jeherve_custom_sharedaddy_link( $url, $post_id, $sharing_id )
//
The post Jetpack: add UTM monitoring to sharing buttons appeared first on DICKLEUNG DESIGN 2014.

沒有留言: