Loading ...
Sorry, an error occurred while loading the content.

30099Re: Tracking Google Analytics Events with Google Tag Manager

Expand Messages
  • VaBeachKevin
    Apr 1, 2013
    • 0 Attachment
      What it looks like you are trying to do is push a Google Analytics event to the Google Tag Manager data layer, and it doesn't seem to know what to do with it. When you push items into the data layer they need to be name value pairs, not a list of values.

      This scenario may help. I have a site that has Google Analytics implemented using Google Tag Manager. On that site I have some links for Twitter and Facebook. I want to track them using Google Analytics and Google Tag Manager but I don't want to edit the site at all. I want to do it all from within Google Tag Manager. Here's what I did.

      In Google Tag Manager the site I'm working on has one Google Analytics tag with the track type of "page view", and its set to fire on all pages. This is the main tag that counts the traffic. I leave this as is. All of the link tracking will happen from other tags.

      First in GTM I create a Rule called "Social Click Tracking". In that Rule I have it set to use the default macro {{event}}, and I have it equal "socialClick".

      Next since I will want to know the name of the Social Media site being clicked, I create another macro called "Social Media Click Site". This one has the type of Data Layer Variable, and I use the data layer variable name of "socialSite".

      Now I create a second Google Analytics tag, this one with the track type set to "Events". For this tag I have the firing rule set to that rule I created, "Social Click Tracking". I also set some Event Tracking Parameters. Category I set to "Social Media", Action I set to "Social Link Click", and Value I set to the previously created macro Social Media Click Site (those are just a few examples, what you set depends on your specific needs).

      At this point it is ready to start tracking links. All I would need to do is add an onClick to each link I want to track and I'll be all set. But since I did not want to touch the page code in any way, I will create another tag to handle that part for me. This time I create a tag with the type of "Custom HTML Tag". This is where I add a little bit of jQuery that will listen for clicks on links that have the class attribute of "social" (which the links I'm interested in do), and then push the events to the GTM data layer:

      var a=$(this).html();

      I see all the link clicks firing with the correct data.

      Let me know if you are still having problems getting it working, I'm happy to help.

      Kevin Rogers

      --- In webanalytics@yahoogroups.com, "baphil78" <baphil@...> wrote:
      > Hi,
      > I'm having a similar problem with tracking custom events. We just installed Google Tag Manager two weeks ago and are working the kinks out. There are several events we are trying to track; one (supposedly) easy one is a newsletter sign-up. Below is the custom JavaScript tag. We created a tag in GTM set it to fire on pages containing "/newsletter", where the sign-up form is. The tag is set to fire when someone clicks the submit button on that page. Though it's written to capture name and email, all we really care about is knowing if someone clicked on it. GA has constant of 1 when this tag is fired.
      > Unfortunately, we aren't getting any data in GA (I've signed up using different emails on different browsers). When I open the debug window in Chrome, it looks like the below tag is firing. Any clues? Would more information help understand this problem. Thanks Kevin, or to anyone who can offer insight.
      > <script>
      > jQuery(function () {
      > jQuery("#form > div:nth-of-type(2) > input").click(function () {
      > var name = jQuery("#fname").text();
      > var email = jQuery("#email").text();
      > dataLayer.push(['_trackEvent', 'Newsletter Sign-Up', 'Name', name]);
      > dataLayer.push(['_trackEvent', 'Newsletter Sign-Up', 'Email', email]);
      > });
      > });
      > </script>
      > Brian
      > --- In webanalytics@yahoogroups.com, "VaBeachKevin" <vabeachkevin@> wrote:
      > >
      > > Actually yes, you can track clicks of links (or buttons or whatever) using Google Tag Manager, without needing to make any changes or additions to the page or the link itself. The way I do it is to add a new tag in GTM with the type of "Custom HTML Tag". In there I use some jQuery to listen for clicks of certain elements on the page, and in that function I add my dataLayer.push calls to trigger events in GA (or any other analytics tool I have being served through GTM). I can add any click tracking to any element, and will never need to make any changes to the html of the page.
      > >
      > > Kevin Rogers
      > > @vabeachkevin
      > >
      > >
      > > --- In webanalytics@yahoogroups.com, "ju2ltd" <jim@> wrote:
      > > >
      > > > Is there a way to tag events such as a button click using Google Tag Manager without the need to call _trackEvent as the onclick event. In other words with out the need to involved developers or html code at all.
      > > >
      > > > May be this is too much too expect!
      > > >
      > > > Jim.
      > > >
      > >
    • Show all 8 messages in this topic