Google Optimize – How to Track Button Clicks

Google Optimize is Google’s A/B testing platform that lets you build variants of your site and run experiments to determine which version performs the best. Without additional configuration, you can choose among the following default experiment objectives: Bounces, Pageviews, Session Duration, and, if you have an e-commerce site, Transactions and Revenue.

This is a nice start, but insufficient if you’re trying to optimize CTA (call to action) buttons for conversion. These CTA buttons may include important actions like Add to Cart, Contact, Download, etc., which are all common targets for A/B testing improvements. This blog post will describe step by step how to track and test button clicks through Google Optimize, to see if the modifications you make to your website make the user more likely to click a button.

Note: testing button clicks in Optimize requires that you first implement Google Analytics event tracking on the button. Implementation typically requires front-end development skills like working with JavaScript and CSS selectors. Step 5 has more details on that.

NEW! API CONNECTOR ADD-ON FOR GOOGLE SHEETS

Check out my new API Connector Add-on to import data from thousands of platforms (e.g. Shopify, Harvest, Mailchimp, ActiveCampaign, VWO, YouTube, etc.) directly into Google Sheets.

STEP 1: CREATE AN EXPERIMENT

From the main page, click Create an Experiment, and fill in the following options:

  • Name
  • Experiment URL
  • Experiment Type (A/B Test, Multivariate Test, Redirect Test)

For this example, I’ll do a simple A/B test of a Contact button on my own site.

optimize-clicks-img1

 

STEP 2: ADD A VARIANT

From within the experiment details page, click Create Variant and give it a name. Once it’s added, click Save.

optimize-clicks-img2

STEP 3: EDIT VARIANT IN THE EDITOR

Hover over the new variant and click the row to make changes in the editor. This will open up the visual editor, where you can select and edit elements. For this example, I’m changing the color of a Contact button from blue to red, using the editor palette.

optimize-clicks-img3

Following these changes, click Save and then Done in the top right to return to the Optimize experiment setup page.

STEP 4: CONFIGURE EXPERIMENT OBJECTIVES

The experiment objective identifies what your test is optimizing for. Under Configuration > Objectives > Experiment Objective, you’ll see 2 options: ‘Choose from List’ and ‘Create custom.’

optimize-clicks-img4

Choose from list will provide the previously-mentioned list of default options: Bounces, Pageviews, Session Duration, Transactions, Revenue, and any goals you’ve previously established in your GA account.

Since we want to track button clicks, you will instead select ‘Create custom’.

STEP 5: CONFIGURE CUSTOM EVENT OBJECTIVE

After choosing ‘Create custom’, name your custom objective and click Events. This will open up a rules matching wizard where you can enter in the Event Category, Action, or Label that applies to your click action, as well as limit it to certain pages if you want. You will also need to choose your counting method (once or many times per session).

optimize-clicks-img5

Note that these events must be tracked in Google Analytics, and the event names for category, action, and/or label that you enter refer to the names by which they appear in Google Analytics. The example above uses “Event Action Equals Clicked Contact Button”, so the tag in GTM must contain an Event Action of “Clicked Contact Button”. This means that you must set up Google Analytics event tracking on the button before you can begin the experiment, and the event tracking must fire on both the original variation and any test variations.

Setting up GA event tracking in GTM is a very big topic in itself (this blog has a dozen posts on the topic) so this post won’t go into it to deeply, but below is a summary of how to set up event tracking on the button.

  1. In GTM, navigate to Tags >  New > Google Analytics – Universal Analytics > Track Type = Event. Fill it in as follows:
    Event Category = Homepage
    Event Action = Clicked Contact Button
    Event Label = leave this empty
  2. Under Triggering, add a Trigger using the CSS selector of your button (e.g. Click Element Matches CSS Selector .button, .button *)
    optimize-clicks-img8
    You’ll need to substitute in your own CSS selector where it says .button, .button *. Step 6 in this post has some info on how to identify your CSS selector, and/or you can try a tool like the Copy CSS Selector Plugin to do it automatically.
  3. Save, Preview, and Publish your container.

STEP 6: CONFIGURE TARGETING

Click the Targeting tab and choose the percentage of visitors to target, the weighting of visitors, and when to show the experiment. To avoid a “Page modified after initial load” error message, make sure that the ‘URL matches’ condition is set to the page you want to run the experiment on (you may see a different URL if you’re copying/modifying an earlier test rather than starting from scratch).

optimize-clicks-img6

STEP 7: RUN THE TEST

Click Save and Start the Experiment.

Happy testing 🙂

 

[OPTIONAL] APPENDIX: ADD TRACKING FOR GOOGLE ANALYTICS

The above is all you need to track 2 different color variations against one another in Google Optimize. However, as implemented above, both variations will be tracked the same way in Google Analytics, like this:
Event Category = Homepage
Event Action = Clicked Contact Button

If you want the event to differentiate the button color in GA, you can add in the following:
Event Label = {{color}}, where {{color}} is ‘Red’ or ‘Blue’

The steps to implement this are as follows:

  1. While editing the variant in the editor (Step 3 above), right-click the button and click Edit HTML. Slightly modify the button code to include the new color — this will let you identify the color in Google Tag Manager.
    optimize-clicks-img7
    Original code:
    Edited code:
     
  2. In GTM, navigate to Variables > User-Defined Variables > New > Custom JavaScript and enter a script that pulls out the information you need from the source code, which we added above to the button HTML. This script checks if the button has a class named ‘red’. If so, it returns the value ‘red’; otherwise it returns ‘blue’.
    Name the Variable ‘JS – Button Color’ and Save it.
  3. In GTM, navigate to Tags >  New > Google Analytics – Universal Analytics > Track Type = Event.  Replace the empty Event Label slot with {{JS – Button Color}}.
  4. Save, Preview, and Publish your workspace containing the new Variable and modified Tag. You should now see the button color reflected in your Event Label.

 

Comments:21

      1. The part of setting up GTM to correctly work with Optimize. Not exactly clear for those of us who are new to this. What name exactly is supposed to be used for “event names that you enter refer to the names by which they appear in Google Analytics” – would this be the Event Category? Action? or Label that we created in the Tag Configuration? Or none of these?

      2. “event names” = event category, event action, and/or event label. If you’ve entered an Event Action of “Clicked Contact Button” in GTM’s tag configuration, then you’d set Event Action Equals “Clicked Contact Button” in Optimize. The names need to match between the systems.

    1. You can extract the information with a script. I added in some information on that, please take a look and let me know if it answers your question.

    1. You again? It explains how to track button clicks, including the exact tag and trigger setup — you just need to substitute in your own button’s CSS selector. Do you have a specific question about it?

  1. Yeah the tutorial is nice, but I agree with “Anonymous” on the fact that this part is not clear (unless I am very dumb and didn’t get it). At the end of Step 5, you’ve created a tag & trigger & variable in orde to track your specific button clicks and attributed a name to each of them. We can now start again at the beginning of Step 5 but where do you enter this tag/trigger/variable in optimize.google ? Do we have to replace “Clicked Contact Button” by the something we’ve created with GTM ? I hope I was clear in my questions. Thanks for the rest though

    1. Hi Sebastien, in the example, I named Event Action in GTM as “Clicked Contact Button”, so I selected Event Action Equals “Clicked Contact Button” in the Optimize Objective configuration page. (Step 4 shows how to access the Objective configuration: “Under Configuration > Objectives > Experiment Objective, you’ll see 2 options: ‘Choose from List’ and ‘Create custom.’…Since we want to track button clicks, you will instead select ‘Create custom’.”)

      If you name your event something other than “Clicked Contact Button” in GTM, then you’d use that name instead in Optimize. Please let me know if that answers your question.

  2. Thanks for posting this, it was really helpful! Keep on the great work.
    For my case I had to compare the values on some inputs for an A/B test, just took me a few tweaks of your solution to achieve this.

  3. Hi Ana. I wanted to add my thanks here. The post wasn’t initially about what I was looking for, but I decided to read through it anyways. I only run redirect tests and was looking to track phone clicks through Optimize so I could have all of my data easily displayed in one place. Step 5, in particular, showed me exactly what I needed to do, and it works beautifully. So thanks!

    1. I know what that’s like, digging through a post to find the relevant slice of information. Thank you for persevering, I appreciate the comment!

  4. Hi, Ana.
    I find your article useful and enough eloquent if there is a decent knowledge on GO and GTM. I liked the part with tracking the color version in GA.
    Thank you!

  5. Thanks for this, It’s made my task to get this exact test working in Optimise so much simpler than gazing at the documentation for 30 hours XD

  6. Hi. Thank you for this article. I have made an event using GTM by following the instructions you gave. I am not sure why GO is still giving me this notification even without doing edits in the first place– “Page modified after initial load…”

Leave a Reply

Your email address will not be published.