AdWords is now Google Ads. Our new name reflects the full range of advertising options we offer across Search, Display, YouTube, and more. Learn more

Analytics
3.6K members online now
3.6K members online now
Dive into multiple domain (Cross/Sub) tracking, implementing Ecommerce and Enhanced Ecommerce, setting up Event tracking, and Universal Analytics code.
 
Guide Me
star_border
Reply

ga.js and analytics.js event tracking

Visitor ✭ ✭ ✭
# 1
Visitor ✭ ✭ ✭

I encountered a recent hurdle in my Google Analytics career.

 

We have 2 properties: 1 using the old ga.js and 1 using the new analytics.js tracking code.

 

Page A:

  • using ga.js
  • using 'button A'

Page B

  • using analytics.js
  • using 'button A'

 

IMPLEMENTATION

We are tracking OnClick events on "button A". Here's what we added to support backward compatibility:

 

_gaq.push(['_trackEvent','Category','Action','Label']);ga('send','event','Category','Action','Label');

 

TESTING

Page A was able to track events

Page B was unable to track events

 

WHY?

1 Expert replyverified_user
1 ACCEPTED SOLUTION

Accepted Solutions
Marked as Best Answer.
Solution
Accepted by topic author charles p
June 2016

Re: ga.js and analytics.js event tracking

Top Contributor
# 2
Top Contributor

Hi Charles, properties and code type are not related. You can use either ga.js or analytics.js on either property but ga.js has fewer features and is no longer supported.
In your case, you're using multiple methods with one onClick attribute.
My recommendation is to use a function to select whether analytics.js or ga.js is installed and fire the right event type accordingly.

Something similar to:

function sendRightEvent(category,action,label){
  if (_gaq!==undefined){
    _gaq.push(['_trackEvent',category,action,label]);
  } elseif (_ga!==undefined){
    ga('send','event',category,action,label);
  }
}

Of course you could use GTM and not worry about this kind of issue.

VP & Chief Evangelist at Hub'Scan | Contact me
Level 80 Digital Analytics Warrior, KPI Therapist and Keeper of the One True Tagging Plan

View solution in original post

Marked as Best Answer.
Solution
Accepted by topic author charles p
June 2016

Re: ga.js and analytics.js event tracking

Top Contributor
# 2
Top Contributor

Hi Charles, properties and code type are not related. You can use either ga.js or analytics.js on either property but ga.js has fewer features and is no longer supported.
In your case, you're using multiple methods with one onClick attribute.
My recommendation is to use a function to select whether analytics.js or ga.js is installed and fire the right event type accordingly.

Something similar to:

function sendRightEvent(category,action,label){
  if (_gaq!==undefined){
    _gaq.push(['_trackEvent',category,action,label]);
  } elseif (_ga!==undefined){
    ga('send','event',category,action,label);
  }
}

Of course you could use GTM and not worry about this kind of issue.

VP & Chief Evangelist at Hub'Scan | Contact me
Level 80 Digital Analytics Warrior, KPI Therapist and Keeper of the One True Tagging Plan