Categories: Web Analytics

Tracking Traffic from Press Releases in Google Analytics

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:
  • On the target page ), 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.

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
#id=1

New URL
#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! 🙂

Allaedin Ezzedin

VP Analytics Engineering Allaedin wisely guides friends, family and colleagues with honesty and care. He is a long time digital analytics industry veteran leading Cardinal Path’s analytics team with over a decade of experience as a digital marketing and senior analytics consultant.

Share
Published by
Allaedin Ezzedin

Recent Posts

Google Delays Third-Party Cookie Deprecation to 2025

Google announced on April 23 that it will again delay third-party cookie deprecation (3PCD) in…

2 weeks ago

Understanding Funnel Reports in GA4

Funnel reports have long been one of the most actionable reports in a marketing analyst’s…

2 weeks ago

GA4 Monetization Reports: An Overview

GA4’s Monetization reports provide organizations with simple but actionable views into the revenue-generating aspects of…

3 weeks ago

This website uses cookies.