Site icon Robin Heed

See what users are Copying and improve your Website

Installation time: 15 minutes.

A really great way to see what your users are interesting in when visiting your website is to measure if they are copying your texts. Every time a user copies a text it shouts out “I NEED THIS”. This is valuable information in order to improve your website and if e.g a lot of people are copying a phone number, maybe you should create a hyperlink to make it easier for the users to call you. Or you have a great article explaining “How to buy a house” and you can see that many are copying a phrase or a word – maybe you should write more content on that topic or make a poster to explain it even more.

All this can be measured with Google Tag Manager and in just a few steps you can make this go live on your website.

 

Variable

 

  1. First of all. Sign in to your Google Tag Manager account and create a new variable and name it “Copytext-variable”.
  2. From Choose Type use a Data Layer Variable.
  3. The second step in this process you need to configure your variable. In the Data Layer Variable Name choose “clipboardText”. Hit Save Variable.

 

Trigger

 

  1. Create a new Trigger name it “Copytext”.
  2. From “Choose Event” make it a Custom Event.
  3. From the second step Fire On write in the Event name “textCopied”.

 

Tag

 

  1. Create a new Tag and name it “Text Copied”. This tag will send the data into Google Analytics every time a user copy a text from your website.
  2. Choose Product, select Google Analytics.
  3. Choose a Tag Type, I bet you are using Universal Analytics.
  4. The next step is to configure the tag. From the Tracking ID you have two options. Either you can copy/paste your UA-id into the field. Instead of doing this every time you are creating a new tag you can simply create a new variable and name it “UA”. The Choose Type use Constant and in the last step Configure Variable and in the field Value insert your UA-id. Voila!
  5. As Track Type choose Event.
  6. Category: Text Copied.
  7. Action: Choose from the +, Copytext-variable.
  8. Label: Page Path.
  9. Fire On: From More choose Copytext.
How to make a UA variable.
Text Copied Tag

The last step is to tell Google Tag Manager what the variable, trigger and tag should do. And in this post we want an event when any user on any page is copying a text. To do this we need to create a tag to connect everything together – Custom Listener tag. Here it is:

 

Custom Listener Tag

 

  1. Create a tag and name it custom Listener.
  2. Choose Custom HTML Tag.
  3. Now we are going to tell GTM how a text is copied. Copy/paste the HTML below into your tag.
  4. Fire On – All Pages. Click Save Tag.
// Copy the text below
<script>
// Declare function to get selected text from document
function getSelectionText() {
var text = "";
if (window.getSelection) {
text = window.getSelection().toString();
} else if (document.selection && document.selection.type != "Control") {
text = document.selection.createRange().text;
}
return text;
}
 
// Declare function on copy event
document.addEventListener('copy', function(e){
dataLayer.push({
'event': 'textCopied',
'clipboardText': getSelectionText(),
'clipboardLength': getSelectionText().length
});
});
</script>
Custom Listener Tag

Now everything is set. You can now preview the tag to see if it’s firing into Google Analytics.

Go to your website and copy any text on your site. Open your analytics account and choose Real Time > Event. Publish the tag. GG!

You can see all this data in Behavior > Events > Overview. Now it’s up to you to make the user experience even better!

Did you like this? Brag to your colleagues about your new skill and share it!

Exit mobile version