XF 1.2 Adding utm code to urls generated via share page?

william1872

Member
Hi all,

I'm wondering if the following is possible at all?

I'd like to add a utm tracking code to the end of urls / pages shared via the 'Share Page' social icons.

The main purpose is to see how many click backs to our site is being generated as a result of a post being shared socially, some of our posts can generate 100+ shares via twitter / fb and g+.

Would it be the case of adding the utm code in the share_page template in the following section?

Code:
<xen:if is="{$xenOptions.plusone}">
                <div class="plusone shareControl">
                    <div class="g-plusone" data-size="medium" data-count="true" data-href="{$url}"></div>
                </div>
            </xen:if>

And change it to:


Code:
<xen:if is="{$xenOptions.plusone}">
                <div class="plusone shareControl">
                    <div class="g-plusone" data-size="medium" data-count="true" data-href="{$url}?utm_source=JVFocus&utm_medium=GPlusSocialShare&utm_campaign=JVFSyndicationCircle"></div>
                </div>
            </xen:if>

I don't know much about coding, however for us to be able to track what traffic all the social shares are pulling back would be a very useful martic for us.

Thanks in advance for advice :)
 
Yeah the code you posted would add an additional query string at the end of the URL being shared. The link will only work correctly if you have full friendly URLs enabled.

If you do not have friendly URLs (e.g. you have ?index.php at the end of your URLs already) then you would replace the ?utm_source with &utm_source.

But presumably you will have friendly URLs enabled so that should work.

Your example would only work for Google +1 button though, you'd have to do a similar thing for Twitter and Facebook.
 
One thing that just occurred to me is that twitter urls aren't shortened via the twitter share button and adding the utm code to the end would make the tweet too long.

Anyone know how to shorten the urls in xenforo for twitter shares?
 
Looks like Facebook strips the UTM code out? Twitter and G+ works a treat for the tracking...

Here's an example url that's generated when I FB Share

Code:
http://www.jvfocus.com/threads/why-visitors-not-buying-part-3-of-5-featured-based-thought-process.682/?fb_action_ids=590600004367222&fb_action_types=og.likes&fb_source=aggregation&fb_aggregation_id=288381481237582

And what it should look like with the UTM code on

Code:
<fb:like href="{$url}?utm_source=Social%20Share&utm_medium=FB%20Like&utm_campaign=Syndication%20Circle" show_faces="true" width="400" action="{$xenOptions.facebookLikeAction}" font="trebuchet ms" colorscheme="@fbColorScheme"></fb:like>

Not quite sure if there's a way around that so the UTM code stays in place for tracking clicks back to the site?
 
Hmm yeah it looks like it is something that Facebook does itself. It probably only uses the href attribute if it can't ascertain the referring URL by some other means.
 
Back
Top Bottom