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:
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:
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: 
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:
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.
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.
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:
In GA4,click「Admin」——「Custom definitions」——「Custom metrics」——「Create custom metrics」, then do the following configuration:
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:
This allows you to see what users copy most frequently and how users interact with your content.



