0

On my webpage I have 3 button ( Good ,Average, Bad). I want to track how many times particular button is click. I want to use custom dimension and custom metric to track this in below format

Button Name    No.of time button click
Good             5
Average          10
Bad              5

I have created custom dimension, DataLayer Variable (in GTM V2), custom metric. I am not able to write the DataLayer code (DataLayer Creation & DataLayer Push method) code to track the counts how many time a particular button is clicked as I am not a developer or coder . Can someone please help me with the code of DataLayer that I can paste/code on my webpage so that click value for button is passed to custom metric I have created. DataLayer name that I have created in GTM V2 is BottonClicKToTrack. Also do I need to define Event for the same.

Horizon_Net
  • 5,959
  • 4
  • 31
  • 34
Avez
  • 1
  • 4
  • Any one can help me on my above issue/request – Avez Jul 09 '15 at 08:23
  • You can use built in Universal Analytics Event tag to track button clicks and analyze this data. – mrbubu Jul 10 '15 at 11:53
  • Thanks Mrbubu, But if you can just elborate you suggestion on how can i implement that using custom metric it would be great help. Also I am new to GTM and GA so might take time to understand any suggestion apology for that – Avez Jul 10 '15 at 13:16
  • Also if you can help me in my other query that I have posted Thanks in Advance – Avez Jul 10 '15 at 13:17
  • If your goal is only to see a number of click on different button, then GA events is all you need. If your goal is broader, please give more information about it. – mrbubu Jul 11 '15 at 08:35

2 Answers2

0

You don't necessarily need to insert anything into the datalayer to accomplish what you're asking. You can, but I believe there is an easier way.

1) Set up 3 triggers, one for each button. Make each button fire when the respective button is clicked

2) Set up 3 tags, one for each button. Make each tag send an event to your GA Account with the following information. Category : Button Action : Click Label : Good/Average/Bad

This way you will be able to view your button clicks in google analytics and sort them by label to see which one was clicked more. If you have questions about the implementation please comment and I will post a full detailed solution. If you request a full detailed solution, I would like to see your HTML code for the buttons. Specifically I would need to see something like this

<button id='?' class='?'>BUTTON TEXT</button>

Keegan
  • 179
  • 8
  • Thanks Keegan for the solution you suggestion sound good but the problem is that my client wants it be done using custom metric / dimension and using dataLayer function. If you can help me on that. I am not developer so find it difficult to write dataLayer code and also i am not good with dataLayer concept. If you can help it would be really helpfull to me. Thanks in advance – Avez Jul 24 '15 at 11:37
0

Avez, You need to place the data layer code above your GTM Script tag. Like so.

  <body>
  <script>
    dataLayer = [{
      'good': 0,
      'average': 0,
      'bad':0
    }];
  </script>
  <!-- Google Tag Manager -->
  <!-- End Google Tag Manager -->

  <button onclick="incrementCounter('good');" id='goodButton'>Good</button>
  <button onclick="incrementCounter('average');" id='averageButton'>Average</button>
  <button onclick="incrementCounter('bad');" id='badButton'>Bad</button>

  <script>
  var good = 0;
  var average = 0;
  var bad = 0;
      function incrementCounter(b) {
          if (b == 'good')
            good += 1;
          else if (b == 'average')
            average += 1;       
          else if (b == 'bad') {
            bad += 1;
          }
          dataLayer = [{
            'good': good,
            'average': average,
            'bad':bad
          }];
          console.log(dataLayer); /* DEBUG STATEMENT */
      };     
  </script>
  </body>

I left a debug statement inside of the script so you can see what the function is doing. I'm not a huge fan of this approach but it will work. Installing this script into your page (inside of the body tags) will set up the necessary functionality to record button clicks. From here I am not sure what you are asking for. Perhaps start with this and let me know what else I could do.

Keegan
  • 179
  • 8