How to Track Highlighted Text on Your Site with Google Analytics

For today’s post, I’d like to introduce James Morell – a well known UK SEO working in Bristol. Next time you see him – buy him a beer. I’m personally delighted to have him (working alongside Sam George) on the Builtvisible blog and you are simply going to love the fruits of their labour!

Losing visitors to search?

Have you ever wondered where you’re losing visitors to search from? How about finding out which pages you should be internally linking to better? A simple piece of JavaScript added to your pages can work wonders.

A few assumptions to get out of the way first. We all know, or at least suspect, that people on our sites are highlighting text, right clicking on it and selecting “Search Google For…” If they’re not doing that, they’re highlighting the text, copying it and pasting it into Google. Often you’ll have content on your site that people could be looking at instead of going off elsewhere, possibly to one of your competitors, and finding out more about.

We also know about services like Tynt, which is really useful for publishers wanting to know where content is being copied to, and adding in links for you.

Tynt recently added a service that shows you the most copied short pieces of text on your site – what they call ‘search copies’ – which is an incredibly useful service. I however wanted to take it a step further. If I know the text that is being highlighted, I want to know which page it is on, so I can look at my internal linking strategy, and I want to see pages that are getting a lot of text copied from them.

In a fortunate coincidence, Sam was working with Get_Selection in JavaScript anyway, so I persuaded him to take a look at the issue. The conclusion we came to was Google Analytics‘ event tracker is awesome, and Sam is a JavaScript demon and my new hero.

What Sam has created is a piece of JavaScript which when added to your site shows you which words or phrases from 3 – 50 characters are highlighted on your site. This then fires off an ‘event’ in Google Analytics and allows you to see exactly what is highlighted within the event tracking section of ‘content.’

So how do you do this? Easy. Get the highlighted word tracking script and follow the instructions there.

google code

Place the code above or below (doesn’t really matter) your Google analytics as follows:

Once this has been running for a few days you’ll see results like this:

screen 1 analytics

So far this is no different to what you’d see with Tynt, however, by using Google Analytics to do the heavy lifting for us we can add ‘page’ as a dimension so we can see which pages those pieces of text are being highlighted on. Obviously you can change the secondary dimension again, so you could see which words and phrases UK visitors are interested in, you could use another analytics profile to see the pages that UK visitors are interested in, or you could apply a user defined dimension, the possibilities are if not limitless, pretty damn big!

An example of which pages have had phrases copied from for starters looks like this:

screen 2 analytics

One of my personal favourites is to export the data to Excel and look at page based information and see which pages are having which pieces of text highlighted on them – do you need to internally link to a large chunk of text, or will a small piece do? Once you’ve got the information in Excel you can also use the concatenate function – every SEO’s favorite – to run a site: keyphrase search to discover which piece of content you should be linking to internally.

For those that don’t know, export the data from analytics, and in column k, add:


Copy this down your row and you’ll be able to copy and paste the results out to Google to see which pages it sees as most important on your site for the terms being highlighted and you can then either reinforce these by internally linking to them from the pages where highlighting is happening, or you could try and boost the importance of another page on site for the term – your choice. Either way you’re helping your site visitors to find the content on your site, or you’ve got a great idea of affiliate links you should be placing.

I hope that this code will prove useful – I really look forward to seeing how people use it and what other ideas people come up with based on the segmentation that you can perform in Google analytics, and let us know in the comments any other ideas you might have!

Learn More

Builtvisible are a team of specialists who love search, SEO and creating content marketing that communicates ideas and builds brands.

To learn more about how we can help you, take a look at the services we offer.

Stay Updated

Follow: | | |

Tags: , | Categories: Technical

27 thoughts on “How to Track Highlighted Text on Your Site with Google Analytics

  1. Carl Hendy says:

    Another great post on the SEOgadget blog and no mention of the word [Ninja] great stuff James & Sam.

  2. Sam Crocker says:

    My gracious, another cracker from you guys! Keep this sort of stuff coming. Always love some handy GA hacks and love to find a new one every now and again. Great work James and well done Rich for highlighting this.

  3. Hey Sam – yeah I just want to say that when I spoke to James about this idea I had to have him post about it! This has been one of the most exciting hacks to see developed and James and Sam really deserve a round of applause and a beer!

  4. Simon Cooper says:

    This looks like a really useful script, which I’ll have a play with.

    Just thought I’d mention a service that dort of does something similar and that is

    The main idea of these guys is to show you things like twitter users, wikipedia pages etc whilst on your site, and not have them leave. It also has a feature where you can highlight text and it shows a bunch of results etc.

    All of this can be reported on.

  5. gue5t says:

    *Don’t do this*. If your users give a flying **** about privacy they’ll find out, be creeped out, and probably block your site as malicious and untrustworthy, and maybe in passing mention how terrible it is to their friends. This is creepy as hell, guys, and honestly most of the data is just going to be people highlighting lines of the article as they read them.

    Also, selecting text and copying it into the search box? I do that when I want to look for the exact same article or quote someplace else. Otherwise why wouldn’t you just type what you mean into a search engine?

  6. Those same people can block the analytics tracking script if they like. This hack is no different privacy wise to tracking a clicked link, internal search or an exit click IMO.

  7. I can think of a few cool uses for this, thanks for the great tip about how to go about doing it. :)

  8. Or you could just sign up at as it’s a free service, and works on all the popular browsers, and provides a bunch more options, graphs, and cool features…

    I should probably mention that I work at Tynt. ;)

  9. Hey Eric – it was a good thing you mentioned you worked at Tynt. Yeah – Tynt is cool – it’s more powerful than this solution and definitely worth a try.

  10. Richard,

    Check out some of the cool stuff we’re doing with the datastream of copies and stuff flowing by:

    There’s even a developer API for people to play with! Are we a cool company or what?

  11. ce-livre says:

    Merci pour le tuyau sur la façon de m’y prendre.

  12. McCoy Pauley says:

    Thank your for confirming once again that the S in SEO stands for sleazy.

  13. Adrian says:

    gue5t may have used somewhat alarmist language, but he has a point. For anyone wanting to behave ethically, surely the site’s privacy statement should make reference to this and any other visitor tracking methods? Let’s face it, your average punter on a non-techy site wouldn’t know an analytics tracking script if it kissed them full on the lips (no tongues, that would be wrong).
    Given that some countries have much tighter laws on declaring use of cookies etc, I think some sort of opt-in / opt-out clause has to be put somewhere, no? Or has this sort of ‘feedback’ been normalised to such an extent that we’re all comfortable with it?
    I know that 99 times out of 100 the intent of the developer will not be malicious, but in the same way that call centre companies have to declare that ‘your call may be recorded for training purposes’. Google makes sure to say things like ‘read this – it’s not the usual yad yada’ when they are seeking permission for ‘feedback’. Honesty is the best policy – and as peception plays a big part in user behaviour, people should be aware that there may be a cost to badly implementing this idea.

    What are other people’s thoughts?

  14. Adrian says:


    Tynt actually have a comprehensive privacy policy that explicitly addresses their use of copy/paste info – although their statement that:
    “We do not knowingly collect or maintain PII from individuals who are under 13 years of age” is a bit tricksy (oh look, here’s some Tynt copy/paste linkage!)
    Read more: Tynt » Privacy Policy
    – they knowingly tracked my link, but they don’t know how old I am, so that’s OK, right?

    A savvy user could choose to delete the Tynt #link from the email they’re writing, and presumably the chain is broken. An un-savvy one has just given another piece of the puzzle to any site tracking IPs, Facebook likes, email addresses, tweets, etc etc. For a less scrupulous site owner, it would be fairly easy to design a ‘Briar Patch’ of tempting phrases (, and SEO a likely destination.

    Paranoid? Maybe, but don’t tell me the acai berry brigade’s cogs aren’t whirring right now.


  15. That’s an interesting (and thoughtful!) angle on this idea Adrian. The UX enthusiast inside me says that the data gathered here could be incredibly useful for improving the overall experience, but I couldn’t agree more that honesty and protecting peoples privacy is of utmost importance.

    Suffice it to say, as a user myself, it doesn’t bother me if data is gathered about my actions if those actions are anonymous. Ideally, having your users opt in to a program, and convincing those users that their participation will help the site improve without wasting anyone’s time would be the best approach. I do wonder if this is so much different from tracking what links users click anonymously, or what a user searches for on your site.

  16. Rupert says:

    I think that most people today have no expectations of privacy; we assume that everything will be tracked somehow. what does it matter any way?

  17. Adrian says:

    I agree, the anonymous nature of the data makes it in theory harmless. It’s the capacity for combining this with other ‘covert’ visitor data collection that means abuse is possible. I think we have to be increasingly sensitive to visitors’ perceptions. Here’s a great presentation that speaks to that kind of duty of care:
    (I love the RyanAir moment :) )

  18. Hello!
    Just wanted to let you know that it doesn’t work because of this issue:

    d = cnt(sel_text);
    if (sel_text != null && d min_len) {
    _gaq.push(["_trackEvent", "CopyText", "Highlighted", sel_text]);

    Google analytics allows you only to track numerical values, so you’ll need to replace this piece with

    d = cnt(sel_text);
    if (sel_text != null && d min_len) {
    _gaq.push(["_trackEvent", "CopyText", "Highlighted", d]);

    That one tracks the length of the selected text :)

  19. Hi Marco,

    I’ve passed this on – thank you for spotting that, I’m sure James / Sam will follow this up pretty quickly. Certainly the text itself is getting into even tracking (I can see plenty of data).

  20. I got to correct myself… My fault… Didn’t understand this tracks events using labels :) It’s ok, false alarm :)

  21. I totally agree with gue5t on this

  22. Steve Barnes says:

    Awesome Post, you guys are awesome!!!

  23. Its a terrific….Never thought about it….a simple one yet powerful tool…thanks guys…keep them coming…

  24. Sean Browne says:

    Thank you guys, some great info here. I wasnt even aware of tynt. I am going to check it out and also implement the Javascript. (btw, interesting discussion on privacy too!)

  25. JWC says:

    If this script is so good, can you tell me why you don’t use it on this blog?

Leave a Reply

Your email address will not be published. Required fields are marked *