How to organize ABn testing through Tag Manager

Step 1: Create your own events in Google Analytics

Step 2: Create a sending code

_gaq.push(['_trackEvent', 'category', 'action', 'opt_label', 'opt_value', 'opt_noninteraction']);
onclick
<button id="my_btn" onclick="_gaq.push(['_trackEvent', 'category', 'action', 'opt_label', 'opt_value', 'opt_noninteraction']);">My Button</button>
var TransferBtn = document.getElementById("transfer");
TransferBtn.onclick = (function() {
_gaq.push(['_trackEvent', 'category', 'action', 'opt_label', 'opt_value', 'opt_noninteraction'])
})();
  1. category
  2. action
  3. opt_label
  4. opt_value

Step 3: How to send data to GA through the dataLayer

  1. Go to the “Triggers” section and create a trigger with the “Custom event” type there.
  2. In the name of the event we write any name. This name will be the activation condition for our script, which will send data through the dataLayer.
  1. Use as category, action, label, and value our previously created custom variables: eventCategory, eventAction, eventLabel, eventValue.
  2. Activate the event by the trigger we created (user event) — event-to-ga.

Step 4: Complete the listening code and publish it in the Google Tag Manager container

var TransferBtn = document.getElementById("transfer");
TransferBtn.onclick = (function() {
_gaq.push(['_trackEvent', 'category', 'action', 'opt_label', 'opt_value', 'opt_noninteraction'])
})();
dataLayer.push({‘event’: ‘event-to-ga‘, ‘eventCategory’ : ‘category_value’, ‘eventAction’ : ‘action_value’, ‘eventLabel’ : ‘label_value’, ‘eventValue’ : ‘value_value’ });

Step 5: Checking that the code works

How to organize ABn testing through Tag Manager

--

--

--

UI designer who codes on a freelance basis. I’m on my way to become a UX (Product Designer) in a large company.

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
azamat.design/

azamat.design/

UI designer who codes on a freelance basis. I’m on my way to become a UX (Product Designer) in a large company.

More from Medium

IBM SPSS Statistics — Project NX wins a 2022 Indigo Design Award

‘Quiet as they come’.

On Demand Skills in the Field of Design

How we crushed our user testing in only 13 days