Google Tag Manager Practical Guide:Track user replication behavior | BCS Google Tag Manager Practical Guide:Track user replication behavior | BCSBCS

Google Tag Manager Practical Guide:Track user replication behavior

Google Tag Manager BCS 5 years ago (2019-12-18) 3296 Views 2 Comments

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:

Google Tag Manager Practical Guide: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:

Google Tag Manager Practical Guide: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.

Google Tag Manager Practical Guide: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:

 

Google Tag Manager Practical Guide: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.

Google Tag Manager Practical Guide:Track user replication behavior

 

Google Tag Manager Practical Guide:Track user replication behavior

Tested successfully, can be published

 

Warning: Google Analytics is not allowed to send PII information. If you want to send it, please encrypt it first. This article is for demonstration purposes only. This blog does not collect user PII  info.


If you don't understand, You can leave a comment below.
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