简体   繁体   中英

Mobile tracking google analytics and google tag manager

I want to track how many user click the call button on the website in mobile view. The concern is that call button is placed on two pages having same code.

I have place the below code to track the activity.but since the same code is placed on two different page. I am not able figure how many user click from which page. Page url is static it doesn't change.So we are using event tracking the differentiate. I have attached screenshot of the GTM & Web pagecode. The line highlighted in grey in image is were the phone no. & class code ( i could not share the mobile no. & class due to security). Also i have highlighted the only class that differ in code ( " pane-bean-additional-resources-about-trume" & pane-bean-safety-and-dosing-banner")

         jQuery(".bw-mobile .ga-dosipage").click(function() { 
      try {
          dataLayer.push({
        'event': 'lear-more',
        'category': 'Call',
        'action': 'Click',
        'label': 'Page - abc'});
         } catch (err) {}
       });

在此处输入图片说明

在此处输入图片说明

Can any body assist me with change in code at GTM level.

Thanks in advance.

If that css class is the differentiating factor you can use some JavaScript to check which version you are on. The code could look like this:

function getPageVersion(){
  var page = document.querySelectorAll(".pane-bean-safety-and-dosing-banner");
  if(page.length>=1){
    return "Page Version A";
  }else{
    return "Page Version B";
  }
}

This will return "Page Version A" if it can find that css Class on the page and return "Page Version B" if it can't. This way you can change:

'label': 'Page - abc'

to:

'label': getPageVersion()

If you want a pure GTM solution just put the code I put above in a Custom JavaScript Variable (don't forget to remove the function name). You can then use {{NAME OF THE GTM JS VAR}} in the Event Label part of the Analytics Tag and set the Trigger to Click , any click , enabled on the page the button is on, and filter to Click Class contains whatever your button class is.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM