1. Home
  2. Docs
  3. Google Tag Manager Guide
  4. Google Tag Manager Practical Guide
  5. Track User Replication Behavior

Track User Replication Behavior

Many websites will leave contact information on the page, and hope visitors can get in touch with you through contact information, such as email. This time I shared the copy behavior in GTM, mainly because the user copied the contact information on the page.

Principle: Inject js through the page, determine whether the user has a copy behavior, and actively push the event. At the same time, pass the copied text information to the data layer variable. The latter is to use the trigger and data layer variable to receive the corresponding value. Use the event in the code. Tracking sends relevant information to the Google Analytics.

By tracking the user’s copy through GTM, you can know what the user copied, what page it was copied on, what time period was copied, and which channel the user concentration was copied in. This information can be supported by advertising on channels and time periods.

Setup process

1、Inject JS

Listen to the user’s copy behavior through a piece of js code. Because this code will use some interfaces of the browser, all parts of the browser will not be tracked if the interface is closed. At present, this method can track most of the Browser

<span style="font-size: 12pt;"><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>
</span>

Create an HTML in GTM, and copy the above code into it, as follows:

Track User Replication Behavior

2、Set the trigger condition textCopied

To receive a previously sent event with a custom event, note that the event name must be the same as the event name sent in the previous step:

Track User Replication Behavior

 

3、Receive data layer variable clipboardText

In GTM, the data layer variable in the variable is used to receive clipboardText. In fact, clipboardLength can also be received through the data layer variable, but here it is enough to introduce the specific copy content. The specific settings are shown in the figure.

Track User Replication Behavior

4、set the event in the tag

Set in the Tags, send data to the GA, the specific settings are shown in the figure:

 

Track User Replication Behavior

The trigger is the textCopied set in the second step.

5、Preview

 

Test in GA real-time to see if there is a trigger. If there is, it indicates that the event tracking is successful. The success status is shown in the figure. If not, you need to debug to locate the problem.

Track User Replication Behavior

 

Track User Replication Behavior

Tested successfully, can be published

 


If you don't understand, You can leave a comment below.
Tags , ,