0

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!!

asked Oct 24, 2014 at 2:58

3 Answers 3

3

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.

answered Oct 24, 2014 at 3:14
Sign up to request clarification or add additional context in comments.

Comments

0

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.

answered Oct 24, 2014 at 3:11

Comments

0

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.

answered Oct 24, 2014 at 3:19

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.