Veit
Veit

Reputation: 49

Google Analytics Code Returns 'Undefined Function" Error

whatever I do, I keep getting an "Uncaught TypeError: undefined is not a function" error for the click tracking Google Analytics code.

The page is: http://www.purevisionmethod.com/eye-exercises/

Please, why is this happening...?

<script>
$('#clicked-headerbar').on('click', function() {
  ga('send', 'event', 'website-banner', 'clicked-ad', 'headerbar', '0');
});
$('#clicked-cta-bottom').click( function() {
  ga('send', 'event', 'website-banner', 'clicked-ad', 'cta-bottom', '0');
});
$('#clicked-sidebar-image-ad-1').click( function() {
  ga('send', 'event', 'website-banner', 'clicked-ad', 'sidebar-ad-1', '0');
});
$('#clicked-sidebar-image-ad-2').click( function() {
  ga('send', 'event', 'website-banner', 'clicked-ad', 'sidebar-ad-2', '0');
});
$('#clicked-sidebar-image-ad-3').click( function() {
  ga('send', 'event', 'website-banner', 'clicked-ad', 'sidebar-ad-3', '0');
});
</script>

Thanks for your help!!

Upvotes: 0

Views: 3516

Answers (3)

carlodurso
carlodurso

Reputation: 2894

I actually identified this as the offending line:

$('#clicked-headerbar').on('click', function() {
  ga('send', 'event', 'website-banner', 'clicked-ad', 'headerbar', '0');
});

change the .on() to .click() as below:

$('#clicked-headerbar').click( function() {
  ga('send', 'event', 'website-banner', 'clicked-ad', 'headerbar', '0');
});

Not sure why this is happening, however your page is loading two versions of jQuery.

Upvotes: 0

Yahel
Yahel

Reputation: 37305

The error isn't related to Google Analytics.

The error is because you're including the jQuery library after this code which uses jQuery. Move this code below your jQuery include, or move your jQuery include to be before this code, and it'll work.

Upvotes: 3

user4136487
user4136487

Reputation:

First register your tracking id on Google Analytics. Then Google will provide you a block of code which will include some javascript code with your registered tracking id. Put that code into your webpage and then write above code below of Google Analytics code.

Upvotes: 0

Related Questions