« »
Jan 13
2009

You are working on your site’s SEO by publishing press releases and you wish to track traffic to your site from those press releases.  You are not adding source campaign parameters (and therefore no campaign parameters at all) to your links because you are not sure which sites will pick up your press release.

Sounds familiar, doesn’t it?

In Google Analytics, you noticed that links from press releases are tracked as:

  • Source = cnn.com, bbc.co.uk, or domain.com
  • Medium = referral
  • Campaign = (not set)

I am sure you are not satisfied with this basic level of tracking because it does not tell you much, especially if you wish to track across different campaigns and mediums.

The following example makes more sense and will help you evaluate and analyze your campaigns.

  • Source = cnn.com
  • Medium = press_release
  • Campaign = hurricane_katrina

To overcome this challenge of tagging links from unknown sources, I came up with the following trick.

Algorithm:

  • Add a parameter on all links to your site that are in the press release. (example: http://www.mysite.com/myfile.html#id=1)
  • On the target page (http://www.mysite.com/myfile.html), check the value of the “id” parameter.
  • If the “id” parameter equals “1″, replace the parameter in the URL with the following utm parameters (utm_source, utm_medium and utm_campaign) before the call to pageTracker.
  • If the “id” parameter does not equal 1, call the pageTracker function normally.

View the entire code segment.

Let us explore the code, section by section:

var parameter = get_parameter('id');

function get_parameter(name)
{
name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
var regexS = "[\\?&#]"+name+"=([^&#]*)";
var regex = new RegExp(regexS);
var results = regex.exec(window.location.href);

if( results == null )
  return "";
else
  return results[1];
}

This portion of the code will return the value of the “id” parameter from the URL and assign it to the “parameter” variable.

if (parameter == '1')
{
window.location.hash = "utm_source="+srcPage+"
&utm_medium=press_release&utm_campaign=hurricane_katrina";
}

If the page url contains the “id” parameter and its value is 1, then the url will be updated with the utm parameters.

Link URL
http://www.mysite.com/myfile.html#id=1

New URL
http://www.mysite.com/myfile.html#utm_source=www.cnn.com&utm_medium=press_release&utm_campaign=hurricane_katrina

* Notice that we did not use window.location.href function because this function will re load the page with the new URL, which is not what we want to happen. We just want to update the URL, without affecting the visitor experience, in order for the Google Analytics tracking code to attribute the visit in a certain way.

How to get the value of the utm_source (referral site)?

var srcPage = getDomain (document.referrer);

function getDomain (thestring)
{
var urlpattern = new RegExp("(http|ftp|https)://(.*?)/.*$");
var parsedurl = thestring.match(urlpattern);
return parsedurl[2];
}

This portion of the code is responsible of assigning the URL of the referral site to the variable scrPage. The “getDomain” function parses only the domain name (www.domain.com) out of the long url string (http://www.doman.com/file.html?parameter=abc)

The last piece of code that needs to be added is the setAllowAnchor command, which allows the # sign to be used as a query string delimiter instead of the question mark (?).

We used # in the press release link instead of ? for SEO reasons, but you could use ? in the original link and still use the above method.

pageTracker._setAllowAnchor(true);

Alright, now it is time to use our friend Advanced Segments to track our press release visitors, measure their engagement, and analyze their behavior.

Now we can really analyze! :)

Tags: , , ,

28 Responses to “Tracking Traffic from Press Releases in Google Analytics”

  1. Jeremy Aube says:

    Excellent post and great use of the hash code to improve tracking without interfering with the user experience.

    I had one minor question for this line:

    “The last piece of code that needs to be added is the setAllowAnchor command, which allows the # sign to be used as a query string delimiter instead of the question mark (?). This part of the trick is sort of optional. We include it for thoroughness and because using # in incoming links instead of ? is for SEO reasons.”

    It seems like the fact that using ? instead of # would require you to reload the page is a big enough deal that setAllowAnchor wouldn’t really be optional.

  2. Great post and great method. Using the anchor is a good idea anytime you’re creating tracking URL’s that could potentially be published on another site. It prevents the negative impact to SEO and user confusion of parameter-based tracking codes. Nice work!

    -Caleb

  3. Rehan Asif says:

    Hi Jeremy,

    Thank you for your comment.
    What we wrote near the end about the optional part isn’t quite what we meant so I updated the blog post.
    setAllowAnchor is definitely required.
    # in the original link is optional since you could use ? to begin your parameter list and still use the above method.

  4. Rehan Asif says:

    Hi Caleb,

    Thank you for posting.
    I got the idea from you at the GAAC summit and was waiting to make good use of it.
    I have always felt that good web analytics and good SEO can and should go hand in hand.

  5. Thanks Jeremy and Caleb for your kind comments and feedback.
    And for our SEO king, Rehan Asif, thanks for your astonishing help. :)

  6. Still getting an understanding of all this, but I agree web analytics and SEO should work together.

  7. Great Post Allaedin
    Thanks
    Brian

  8. Phil says:

    Is it possible to manually specify the campaign and so on in the actual HTML code?

    i.e. let’s say I know that all visitors who end up at a given url should be part of the same campaign, so mysite.com/bleh.html should always be the ‘bleh’ campaign.

    is there a way in that page’s source code that I can do:

    pagetracker._setCampaign(“bleh”) or even something like trackPageview(/bleh.html?utm_Camp=bleh) or something to that effect?

    thanks

  9. Rehan Asif says:

    Hi Phil,

    Yes that is very much possible.
    We intended the above technique to be deployed on a case-by-case basis.

    So the actual code to get a campaign name of bleh and replace what was in the post might be:

    if (parameter == ’1′)
    {
    window.location.hash = “utm_source=”+srcPage+”
    &utm_medium=bleh_stuff&utm_campaign=bleh”;
    }

  10. Phil says:

    thanks Rehan, this worked great.

  11. Bill says:

    In relation to use of tracking URLs on other sites, Caleb states above “It prevents the negative impact to SEO and user confusion of parameter-based tracking codes”.

    I have a situation where we write articles to promote our company/products and submit to a content syndication outfit. Editors of pubs, papers, blogs, etc. can then use these submitted articles for their use instead of writing content on their own. Since the articles we write get picked up all over the place (not a single referrer), I am using utm/campaign URLs to determine how many times we are receiving visits/pageviews from this syndication network as well as goal completions. Does this actually have a negative impact on SEO or is it neutral?

  12. Rehan Asif says:

    The potential (not guaranteed) SEO problem is that you have the same content available under multiple URLs.
    As you know, this could be a problem and it is preferred to always have one and only one URL for every page.

    And sometimes the URLs with campaign parameters are returned in search results, which places the visit in the wrong medium/source/campaign buckets.

    So you use # instead of ? (along with an update to the GATC) and you can have the best of both SEO and Analytics worlds.

  13. stan oppenheimer says:

    Hi Rehan thanks for the fantastic advice,
    I’ve never seen your blog before fantastic (where’s your twitter link!)

    I have the problem in reverse!
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

    Accurately measuring exits off site via 3rd party links in Analytics.

    I have a scenario where external links all over our Word Press site. I would like to capture data in Google Analytics only when a user clicks one of our external links:

    A) Which page(s) did they click the exit from (Filter for that)
    B) The exact text of the link (Filter filter for that)
    C) The html address of the exit link

    I’m sure there is an elegant-automated way to do this.
    With my limited understanding page exits (Top Exit Pages?)

    I know “Last Page” measurement is impossible to measure! (So I won’t whine about that) – but being able to plot the exit links, that would be something!
    ———————————————————————–

    I am aware you can use Event Tags. But this would mean you would have to manually tag every 3rd party link on a site with event tags! This would become impossible & onerous. And I think there is a maximum number of events Google Analytics will track per unique visitor (500?) – So what do you do for your articles with the the top 100 site links!

    Even worse if you don’t tag those external links properly, Google treats this as a page bounce! The way I see it if somebody bothered to click a link you provided on your site, that’s not a bounce. Its engagement!

    Some one suggested using jump pages-but I’m worried about the user being pissed off by the delay, and the page bloat on the site..

    Is there an elegant way to do this with a PHP / WordPress solution.

    Thanks
    Stan.

  14. Rehan Asif says:

    Hi Stan,

    So basically you want to know points A, B, and C when someone clicks on an exit link.
    But manually tagging all the exit links would be a royal pain.

    Some custom javascript will do exactly what you want.
    We have done similar auto-tagging of external links with javascript but to collect different data (for example, D, E, and F).

  15. Hi Rehan and Allaedin

    Great post. I almost invented the same method but I missed the part with window.location.HASH, which is a really beautyfull solution.

    Tip: The exact same technique can be used to track traffic from search engines to specific “campaign pages” (read: SEO pages). You would then use paramateres like: “utm_source=google
    &utm_medium=organic&utm_campaign=campaignpages&utm_term=” + GetTerm();

    Best regards, Jesper

  16. stan oppenheimer says:

    RE: Nov 4th reply.
    Thanks Rehan

    Yep I think you understand what I’m looking for…
    If you could point me in the right direction, I would be in your debt. Short of spending a year learning PHP myself. Is this a complex solution? Your reply seemed to be cut off..

    Or solution 2 – keep grovelling before our IT guy. (He’ll schedule it in….which means never) :-)

    Stan.

  17. Rehan Asif says:

    Hi Stan,

    Sorry for the short reply.
    Trying to balance knowledge sharing with chargeable work. :)

    The way I would approach it would be with Javascript.
    There might be a way to do it with PHP but I am more familiar with Javascript for click events.

    There is existing javascript out there that can be customized to place onClick events on every exit link.
    As far as I can tell, all three items you want are available with javascript.
    So basically you would customize the onClick event for exit links to get the information you need and send it off.

    Hope that makes sense.

  18. stan oppenheimer says:

    Thanks so much for sharing Rehan,

    I think I know the direction I have to go now, You got to pay to play!
    Thanks for taking the time, to respond.

    Have a great day.

  19. Les says:

    I am just wondering if this methodology will also allow tracking of where (for example) someone who clicks through from CNN goes after they hit the News Release page.

    Great article!

  20. Hi Les,

    Yes it does, if you have links on the press release to your site..

    Let’s say your press release was picked by cnn.com or bbc.com, this hack allows you to track all visits to your site from links in the press release. All activities after that inside your site by the such visitors will be credited to:
    Source = cnn.com or bbc.com
    Medium = press_release

  21. SEO India says:

    Hey Allaedin, thanks sharing your tips & codes. Will implement and check it.

  22. seo says:

    Good one, I got something new to learn here, I will try this code let see how it works.

  23. Jim Bayes says:

    This is pretty smart. I’m going to implement this on our site and post my feedback in a couple of weeks once we collect enough data.

  24. baju branded says:

    . [Trackback].

    [...] Read More Infos here: http://www.e-nor.com/blog [...].

  25. Cheap Flights says:

    Thank to very much for sharing this post with us.
    I Read this post.
    Press release is a way to link building.

  26. Very nice Article. Every One want to know about press Release Traffic. This is a big question How to Track Traffic from Press Releases in Google Analytic. So this post is very useful for thisquestion.

  27. I got something new to learn here, I will try this code let see how it works.Good one..

Trackbacks

  1. Resources for Effective Press Releases | NewVitality News Blog

Leave a Reply