H. Ferrence
H. Ferrence

Reputation: 8116

How to Capture Link Text on Event Click with Google Tag Manager

I want to create a GTM Trigger and Tag to capture the link text and send it to Google Analytics as an event.

I would like to record an event click in Google Analytics anytime the visitor clicks on the a.accordion-title thus setting aria-selected="true". I would like the event to show in Google Analytics with the Link Text -- in my markup below it would be "Accordion 1 Label", or "Accordion 2 Label", or "Accordion 3 Label" so I could tell which accordion element was clicked.

Here is my HTML Markup:

<ul class="accordion" data-accordion="jc8vp5-accordion" data-multi-expand="true" data-allow-all-closed="true" role="tablist">

  <li class="accordion-item" data-accordion-item="">
    <a href="#" class="accordion-title" aria-controls="1y2mly-accordion" role="tab" id="1y2mly-accordion-label" aria-expanded="false" aria-selected="false">Accordion 1 Label</a>
    <div class="accordion-content" data-tab-content="" role="tabpanel" aria-labelledby="1y2mly-accordion-label" aria-hidden="true" id="1y2mly-accordion" style="display: none;">Accordion 1 content...</div>
  </li>

  <li class="accordion-item" data-accordion-item="">
    <a href="#" class="accordion-title" aria-controls="kyorlu-accordion" role="tab" id="kyorlu-accordion-label" aria-expanded="false" aria-selected="false">Accordion 2 Label</a>
    <div class="accordion-content" data-tab-content="" role="tabpanel" aria-labelledby="kyorlu-accordion-label" aria-hidden="true" id="kyorlu-accordion">Accordion 2 content...</div>
  </li>

  <li class="accordion-item" data-accordion-item="">
    <a href="#" class="accordion-title" aria-controls="qt95rx-accordion" role="tab" id="qt95rx-accordion-label" aria-expanded="false" aria-selected="false">Accordion 3 Label</a>
    <div class="accordion-content" data-tab-content="" role="tabpanel" aria-labelledby="qt95rx-accordion-label" aria-hidden="true" id="qt95rx-accordion">Accordion 3 content...</div>
  </li>

</ul>

To help me get started, is this the proper trigger to be setup?

Thank you

Upvotes: 0

Views: 5426

Answers (1)

Alfredo Hinojosa
Alfredo Hinojosa

Reputation: 3

Yes, you almost got the answer.

First you need to be sure that you already enabled all the click related built-in variables, in order to use those values for the trigger and the Tag.

Creating the triggger

  • Select on trigger type = "Just Links" (All elements should be used when the element that is going to be clicked is different than a element, if the element is an anchor use "Just Links").

  • Trigger fires on = "Some Link Click"

  • As the only condition select: Click Classes | Contains | accordion-title

Creating the Tag

Use the following settings as Category, Action and Label (obviously you can change these, the value that you want is inside the variable {{Click Text}})

Configuration of the Tag - Image

And at the end you should be able to see something like this at the Real Time report, on the Events section on Google Analytics.

Real time report GA - Image

Upvotes: 0

Related Questions