Protect your site content with GTM and Google Optimize

December 05, 2022 - Written by

Sometimes, perhaps by searching for your own content in Google, you can come across articles on other sites which, we don’t know how, are identical to the original :D.

Unfortunately this blog is often subject to this practice and the contents copied from scratch are found on other sites: no problem if there are quotes, links to the source, etc. but when they are clearly copy-paste without mention or follow link 😀 .. well it’s not the best.

We therefore asked ourselves how we could avoid this “kidnapping” of contents by third parties without perhaps burdening the site with freemium plugins: the answer was Google Tag Manager and Google Optimize!

At the moment we have identified 3 possible solutions, if you have others to share, they are welcome.

Avoid copying content with Google Tag Manager

The first two solutions, completely independent, concern the injection of scripts via Google Tag Manager on all pages of the site or blog.

Anticopy content: Strong Method

This version of anti-copy-content has been named “Strong” as it eliminates the ability for “copycats” to use the right mouse button or to use the keyboard shortcut cmd+c.

The peculiarity of this script is that it allows you to select the content (highlight) but not to actually use the right button or the keyboard command dedicated to the copy.

The script to insert as Custom HTML is the following:

<script> jQuery(document).ready(function() { jQuery('body').bind('cut copy', function(e) { e.preventDefault(); }); }); </script>

The trigger can be All pages or only on the Blog, News section.. it depends on what you “want” to protect.

Anticopy content: Light Method

Premise: the code was created by Riccardo Mel and you can find the original post at this link.

In this case the right click and shortcut are enabled but when you paste the copied text the phrase “Continue to the site… ” is added: in this way it is possible to limit the copies of the contents and also insert a reference to the original content .

The code to insert in the Custom HTML is the following:

//Copy Shadow Helper
    function copyShadow() {
    //Identifico parte copiata e costruisco div
       var selection = window.getSelection(),
       pagelink = 'Continua su: ' + document.location.href,
       copytext = selection + pagelink,
       newdiv = document.createElement('div');

            //Nascondo il div helper
   = 'absolute';
   = '-99999px';

            //inserisco e popolo il div e setto la selezione con il nuovo div
            newdiv.innerHTML = copytext;

            //Cleanup Helper Div
            window.setTimeout(function () {
                console.log("DP: Rimuovi Anticopy");
            }, 100);

    document.addEventListener('copy', copyShadow); // Listener
    //Copy Shadow Helper

And the result, taking up the previous example, is the following:

This function is very interesting as it allows Google Analytics 4 to be made increasingly flexible and above all adaptable to all digital marketing contexts.

Continue on:

Anticopying with Google Optimize

The latest version to avoid copying of own content is generated through the use of Google Optimize.

For this option we also add a “fun” part to the anticopy as we can decide, for example, to:

  • Show a 404 page only to certain users
  • Showing a completely wrong code only for those arriving from a certain range of IPs
  • Show up a message “I know you’re copying it anyway” to anyone with suitable target characteristics.
  • Much, much more.

Simply access Google Optimize, connected to GA4 (so you can better analyze the data), select Personalization or Redirect and decide on the target users and experiences to submit.

For example, you can set a dataLayer variable where the company network information is passed through GTM, with a specific script:

Once the customization has been set, all users arriving from the corporate network = analytics boosters will see the following post content:

Funny isn’t it?

We should always remember: sharing is caring, stealing is appealing but wrong!


Leave a Reply

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

  • Analytics Boosters

    Vicolo Buranelli, 2
    31100 Treviso

  • Analytics Boosters
    United Kingdom

    41 Devonshire Street
    W1G 7AJ
    United Kingdom

  • Analytics Boosters
    United States

    80 S.W. 8th Street
    33130 - Miami
    United States of America


Contact us