How to Track Text Copying with GTM and GA4

Google Tag Manager BCS 7 years ago (2019-12-18) 4406 Views 2 Comments

Updated: March 16, 2026

Have you ever wondered what people actually do with the content on your site? Beyond pageviews and clicks, there’s one user action that reveals a surprising amount of intent: copying text.

When someone copies an email address, a phone number, a product description, or a key piece of information, they’re telling you they found something valuable. The question is — are you tracking it?

In this tutorial, I’ll show you how to use Google Tag Manager to detect copy events, push the copied text into the Data Layer, and send it all to GA4.

How Copy Tracking Works

The implementation follows a straightforward chain:

  • A Custom HTML tag injects a JavaScript listener onto the page.
  • When a user copies text (Ctrl+C / Cmd+C), the script captures the selection.
  • The copied text and its length get pushed into the Data Layer.
  • A GA4 Event Tag reads those values and sends them to Google Analytics.

Let’s walk through it step by step.

 

Step 1: Inject the JavaScript listener

In GTM , click「Tags」——「New」——「Choose a tags type to begin setup…」——「Custom HTML」,Name it “HTML-Copy”, then add the following JavaScript code:How to Track Text Copying with GTM and GA4

This script listens for any copy event on the page, grabs the selected text, and pushes it into the Data Layer along with its character length.

Tip: If you only want to track specific content — like email addresses or phone numbers — you can add a regex check inside the script so it only fires when the copied text matches a certain pattern.

Step 2: Set up the Custom Event Trigger

Now create a trigger that listens for our new event.

In GTM , click「Triggers」——「New」——「Choose a trigger type to begin setup…」——「Custom Event」,Name it “textCopied”, and make the following settings:

How to Track Text Copying with GTM and GA4

 

Step 3: Create Data Layer Variables

We pushed two values into the Data Layer: clipboardText and clipboardLength. We need variables to read those values.

In GTM , click「Variables」——「New」——「Choose a variables type to begin setup…」——「Data Layer Variable」,Name it “DL – Clipboard Text”, and make the following settings: How to Track Text Copying with GTM and GA4

Similarly, set DL – Clipboard Length.

 

Step 4: Create the GA4 Event Tag

Now create a GA4 Event Tag to send the data to GA4.

In GTM , click「Tags」——「New」——「Choose a tags type to begin setup…」——「Google Analytics: GA4 Event」,Name it “GA4-Event-TextCopy”, and make the following settings:How to Track Text Copying with GTM and GA4

These parameters will pass the copied text and text length to GA4.

 

Step 5 : Preview and Publish

Before publishing, test it. Enable Preview Mode in GTM, open your site, and copy some text. Check the GTM debugger to confirm:

How to Track Text Copying with GTM and GA4

Copy any text on the page and check whether the tag fires in the GTM debugger.

You should also verify that the event parameters contain the correct values.

How to Track Text Copying with GTM and GA4

If everything works correctly, publish the container.

 

Step 6: Register Custom Definitions in GA4

We used two custom parameters — a dimension and a metric — so they need to be registered in GA4 before they’ll show up in reports.

  • TextCopy_text is event scope custom dimensions
  • TextCopy_length is event scope custom metrics

In GA4,click「Admin」——「Custom definitions」——「Create custom dimension」, then do the following configuration:

How to Track Text Copying with GTM and GA4

 

In GA4,click「Admin」——「Custom definitions」——「Custom metrics」——「Create custom metrics」, then do the following configuration:How to Track Text Copying with GTM and GA4

 

Step 7: Verify Data in GA4 Explore

Data usually appears within 24 hours. Once it’s there, go to Explore and build a Free Form report:How to Track Text Copying with GTM and GA4

This will show you exactly what users are copying most frequently across your site.

 

Final Words

Copy tracking is one of those underused analytics techniques that can tell you a lot about user intent. Someone copying a product name might be comparing prices. Someone copying an email address is likely about to reach out. The data is there — you just need to capture it.

Like (3)
Post my comment
Cancel comment
Expression Bold Strikethrough Center Italic

Hi, you need to fill in your nickname and email!

  • Nickname (required)
  • Email (required)
  • Website
(2) friends in the comments
  1. I have been using blogger. com for a while now and I want to see if I can make it pay. It won't let me set up Adsense. But it's made sure that it's taken £10 of me for my domain name. It's not even working anymore ?
    Bbc78782019-12-20 02:59 Reply Mac OS X | Safari浏览器 602.1
    • Third-party blogging platforms generally cannot access Adsense. Need to be your own site, the domain name is your own.
      BCS2019-12-20 09:12 Reply Mac OS X | Chrome 79.0.3945.88