Google Tag Manager Practical Guide:Track Visitors To Add Websites To Favorites | BCS Google Tag Manager Practical Guide:Track Visitors To Add Websites To Favorites | BCSBCS

Google Tag Manager Practical Guide:Track Visitors To Add Websites To Favorites

Google Tag Manager BCS 5 years ago (2019-12-19) 2965 Views 0 Comments

This section is about tracking visitors to add sites to favorites

Principle: The page listens to the event when the user clicks the favorite, and then configures the corresponding action in Google Tag Manager to trigger sending data to google analytics.

Setup Process

1、Create custom HTML

Create custom HTML in Google Tag Manager, and then copy the following code into it:

<span style="font-size: 12pt;"><script type="text/javascript" language=JavaScript>   
      document.onkeydown=function(event){   
            var e = event || window.event || arguments.callee.caller.arguments[0];   
            if(e.ctrlKey  && e.keyCode==68){ 
               dataLayer.push({'event':'AddToFavorites'});
            }else if(window.external.addToFavoritesBar(window.location, document.title)){
                   dataLayer.push({'event':'AddToFavorites'});
            }else if(window.external.addFavorite(window.location, document.title)){
                   dataLayer.push({'event':'AddToFavorites'});
            }
            
         };  
</script></span>

The function of this code is to monitor the user’s behavior of adding the website to favorites, and send the event AddToFavorites when triggered, You can see that there is keyCode in the code. This is the operation of the user on the keyboard. Using a similar principle, you can track some of the keyboard operations when the user visits the website.

Select All Pages as the trigger. The effect after copying the code is as follows:

Google Tag Manager Practical Guide:Track Visitors To Add Websites To Favorites

 

2、Set Trigger

Set a custom event trigger to accept the previously emitted event AddToFavorites

Google Tag Manager Practical Guide:Track Visitors To Add Websites To Favorites

Here is the name of the event you sent in the previous step.

3、Set Tags

Set an event that is triggered when a user adds a favorite and sends data to Google Analytics. The specific configuration is as follows:

Google Tag Manager Practical Guide:Track Visitors To Add Websites To Favorites

Track Type is event, because it is for event tracking. Set the event to a non-interactive type. The trigger is AddToFavorites

4、Preview

Click Preview in the upper right corner and open http://www.bbccss.com to add the website to your favorites:

 

 

Summary

The existing code is only applicable to the tracking of the Window and Linux system, and the Mac cannot temporarily track it. I am researching how to track on MAC.

 


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