Leverage number of keywords in search phrases for long tail analysis in Google Analytics

Hi folks,

Rebounding on a discussion with my colleagues at LunaMetrics, there is definitely a need to measure the impact of the “long tail” in SEO, especially depending on the variety of keywords used. This is called NOK or number of keywords.

EDIT: the impact of (not provided) is felt with this hack. It is still efficient as ever for on-site search, though.

You’ve all seen in your favorite tool to measure how to measure the impact of SEO. You will get reports similar to the one below, which tell you how many such keywords were used in Google and other search engine to reach your site. So far, so good, right?

To monitor organic search performance, you must run regular extracts for a given set of keywords. Welcome to API bliss.

That’s all and good but how about measuring the number of keywords in each search phrase, for both external and internal search?

A quick web search will point you to Google Analytics tutorials on advanced segments handling NOK through regular expressions such as:

^\b\w+\b$

You can change the expression to manage more keywords; you can also create as many segments as you’d like (well, up to 100).

The above solution works but it just does not seem very practical to me.

How about we store the search phrase along with the number of keywords in the search phrase to refine these results?

How? Here is an example with Google Analytics. Of course, this kind of exercise is feasible with other web analytics solutions, but you will probably be more familiar with Google Analytics.

Let’s start by capturing the URL of the page containing your search parameters (ideally, a Google SERP).

– external searches: Google does it all by itself but we’ll help it along!

– on-site search: you must specify a URL search parameter such as q, i, or term.

Example: http://www.monsite.com/search/?q=keyword

Now let’s call a Javascript file via your GATC (Google Analytics tracking code).

Create a file ga_nok.js (that you will need to host on your server) containing the following code:

function getNOK(searchparam,scope,typeNOK)
{
  if (scope==''){ return; } else {
  	searchparam = searchparam.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  	var regexS = "[\\?&]"+searchparam+"=([^&#]*)";
  	var regex = new RegExp( regexS );
  	var results = regex.exec( scope );
  	var keywords = results[1].split('+');

  	_gaq.push(function() {
  	var pageTracker = _gat._getTrackerByName();

  	switch (typeNOK){
	  	case 'NOK': pageTracker._trackEvent('Search', 'NOK',(results[1]), keywords.length, false); break;
	  	case 'iNOK': pageTracker._trackEvent('Search', 'iNOK',(results[1]), keywords.length, false); break;
  	}
  });

  return false;}
};

Now integrate this into the HTML containing your GATC:

<html>
<head>
	<!-- metas, title, JS, CSS, etc-->
	<script type="text/javascript" src="/pathtoscripts/ga_nok.js"></script>
<script type="text/javascript">
	var _gaq = _gaq || [];
	_gaq.push(['_setAccount', 'UA-123456879-1']);
	// Select internal or external search
        if (document.referrer.indexOf('google')>0) getNOK('q',document.referrer,'NOK');
        if (document.location.indexOf('s=')>0)getNOK('s','document','iNOK'); // where s is your internal search parameter
	_gaq.push(['_trackPageview']);

	(function() {
	var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
	ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
	var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
	})();
</script>
</head>
<body>

Page content goes here
</body>
</html>

With this tagging, you are essentially checking for the presence of a search phrase and counting the number of keywords contained therein. Then the search phrase is associated with a “Search” Google Analytics event category. Let us browse to Content > Events:

Great, now let’s look at actions:

So we have “NOK” and “iNOK” listed: NOK for external searches and iNOK for on-site (internal) searches.

Now down to the label level: (click to enlarge)

As you can see, we can now list search phrases (pardon space encoding, I need to fix this someday) along with average value in the far right column. The average event value gives me the number of keywords in the search phrase.

See what I’m getting at? 😉

You guessed it, let’s use advanced filters to show only search phrases that contain more than 3 keywords:

Which yields the following table:

Simple and efficient, right? No more regular expressions, I can now build long tail search segments like a normal human being 😉

Enjoy!

(As always, constructive comments are welcome!)

Leverage number of keywords in search phrases for long tail analysis in Google Analytics was last modified: May 6th, 2013 by Julien Coquet

Julien Coquet

Expert de la mesure d’audience sur Internet depuis plus de 15 ans, Julien Coquet est consultant senior digital analytics et responsable produit et évangélisation pour Hub’Scan, une solution d’assurance qualité du marquage analytics.

A propos de Julien Coquet

Ce message est également disponible en : French