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

Allaedin Ezzedin is a Senior Director at Merkle | Cardinal Path, renowned for his dedication to melding business strategies with technological innovation, particularly in the realm of digital marketing optimization. With an unwavering commitment to enhancing the digital analytics landscape, Allaedin is at the forefront of advocating for Google Analytics as a pivotal enterprise analytics solution.

Share
Published by
Allaedin Ezzedin

Recent Posts

Optimizing user experiences with Digital Experience Analytics (DXA) platforms

As consumers become increasingly digitally savvy, and more and more brand touchpoints take place online,…

1 month ago

Enabling Value-Based Bidding with Google Tightlock

Marketers are on a constant journey to optimize the efficiency of paid search advertising. In…

1 month ago

Resolving “Unassigned” Traffic in GA4

Unassigned traffic in Google Analytics 4 (GA4) can be frustrating for data analysts to deal…

2 months ago

This website uses cookies.