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! 🙂

Message Sent

Thank you for registering.

Cardinal Path hosted a live session to connect with you and answer all your questions on Google Analytics.
Get all the expertise and none of the consultancy fees in this not-to-be-missed, rapid-fire virtual event.

Thank you for submitting the form.

Thank you for submitting the form.

Message Sent

Thank you for registering.

Message Sent

Thank you for registering.

Message Sent

Thank you for registering.

Message Sent

Thank you for registering.

Message Sent

Thank you for registering.

Message Sent

Thank you for registering.

Message Sent

Thank you for registering.

Message Sent

Thank you for registering.

Message Sent

Thank you.

Click here to download access the tool.

Message Sent

Thank you for registering.

Message Sent

Thank you.

Message Sent

Thank you.

Message Sent

Thank you

Message Sent

Thank you

Message Sent

Thank you.

Message Sent

Thank you

Message Sent

Thank you.

Message Sent

Success!
Your message was received.

Thank you.

Thank you for registering.

Cardinal Path is continuing with its series of free training. Next we are conducting training on Google Data Studio. Check it out here.

Message Sent

Thank you for registering.

Thank you for your submission.

Your request has been submitted and a rep will reach out to you shortly.

Message Sent

Thank you for your interest.

Thank you for registering.

You should receive a confirmation email from GoToWebinar with your unique webinar login information. If you do not receive this email or have trouble logging in to the event, please email asmaa.mourad@cardinalpath.com.

Thank you for subscribing!

You're now looped into the world's largest GMP resource hub!

Thank you for your submission.

Thank you for your submission.

Thank you for your submission.

Thank you for your submission.

Message Sent

Thank you for registering.

Message Sent

Thank you for your submission.

Thank you for your submission.

Message Sent

Thank you for registering.

Thank you for registering.​

Paid media spend by Government websites increased a whopping 139% YoY in 2020.

2020 Online Behavior Live Dashboard

Message Sent

Thank you for registering.

Message Sent

Thank you for registering.

Message Sent

Thank you for registering.

2020 Online Behavior Live Dashboard

Thank you for your submission.

Message Sent

Thank you for registering.

Message Sent

Thank you for registering.

Message Sent

Thank you for registering.

Message Sent

Thank you for registering.

Message Sent

Success! Thank you
for reaching out.