1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

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

Discussion in 'XenForo Questions and Support' started by william1872, Feb 1, 2014.

  1. william1872

    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 :)
     
  2. Chris D

    Chris D XenForo Developer Staff Member

    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.
     
    william1872 likes this.
  3. william1872

    william1872 Member

    Thanks Chris

    Yes we use friendly urls, will test this out shortly and let you all know how I get on? :)
     
    Chris D likes this.
  4. william1872

    william1872 Member

    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?
     
  5. akia

    akia Well-Known Member

    I thought twitter shortened them automatically anyway. Try posting a long URL it only takes up 8 spaces.
     
  6. william1872

    william1872 Member

    That's what I thought to Akia however when I tweet a post out, it's the long url that's used?
     
  7. Chris D

    Chris D XenForo Developer Staff Member

    It displays the long, full URL, but it is actually shortened to the 21 character t.co link.
     
    william1872 likes this.
  8. william1872

    william1872 Member

    Ah gotcha, thanks Chris :)
     
  9. william1872

    william1872 Member

    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?
     
  10. Chris D

    Chris D XenForo Developer Staff Member

    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.
     

Share This Page