How to Track Text Copy Behavior with Google Tag Manager (GTM)

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

Updated: March 16, 2026

Copying text from a webpage can reveal valuable user intent. For example, users may copy email addresses, phone numbers, product information, or key content they want to save or share.

In this tutorial, we will show how to use Google Tag Manager (GTM) to track when users copy text from your website and send that data to Google Analytics 4 (GA4).

How Copy Tracking Works

The implementation works as follows:

  • 1、Inject a JavaScript listener using a Custom HTML tag in GTM.
  • 2、Detect when users perform a copy action on the page.
  • 3、Push the copied text and its length into the dataLayer.
  • 4、Send the event data to GA4 using a GA4 Event Tag.

This allows you to analyze what users are copying and how often copy actions occur.

 

Use Cases for Copy Text Tracking

Step 1: Inject JavaScript with a Custom HTML Tag

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 Copy Behavior with Google Tag Manager (GTM)

This script listens for copy events and pushes the copied content and its length into the dataLayer.

Tip

If you only want to track specific content (such as email addresses or phone numbers), you can add conditional logic so that the event fires only when the copied text matches a certain pattern.

Step 2 : Set Up the Trigger

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 Copy Behavior with Google Tag Manager (GTM)

 

Step 3: Create Data Layer Variables

Next, create variables to capture the values pushed into the dataLayer.

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 Copy Behavior with Google Tag Manager (GTM)

Similarly, set DL – Clipboard Length.

These variables will store the copied text and the length of the copied text.

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 Copy Behavior with Google Tag Manager (GTM)

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

Step 5 : Preview and Publish

Use GTM Preview Mode to test the implementation.

How to Track Text Copy Behavior with Google Tag Manager (GTM)

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 Copy Behavior with Google Tag Manager (GTM)

If everything works correctly, publish the container.

 

Step 6: Register Custom Definitions in GA4

Since we created custom event parameters, they must be registered in GA4 Custom Definitions before they can be used 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 Copy Behavior with Google Tag Manager (GTM)

 

In GA4,click「Admin」——「Custom definitions」——「Custom metrics」——「Create custom metrics」, then do the following configuration:How to Track Text Copy Behavior with Google Tag Manager (GTM)

 

Step 7: Verify Data in GA4 Explore

After the configuration is complete, data will usually appear in GA4 within 24 hours.

You can analyze copy behavior in Explore by using:How to Track Text Copy Behavior with Google Tag Manager (GTM)

This allows you to see what users copy most frequently and how users interact with your content.

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