Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6211295
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T06:18:42+00:00 2026-05-24T06:18:42+00:00

I’m trying to use jQuery to find all links on a page, then when

  • 0

I’m trying to use jQuery to find all links on a page, then when they are clicked track the event with Google Analytics.

I have the link part working, I’m just not seeing the tracking work event fire (when monitoring with httpfox).

Can anybody see what I’m doing wrong?

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>jQuery and GA</title>

<!-- This Jquery reference is already on the page -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>

<!-- This script block should go anywhere on the page, ideally the head, or really ideally in the a master scripts file -->
<script>
$(document).ready(function() {

// Each time a link is clicked, this function gets called
$('a').click(function(){

// Get the url
var url = this.href;        


// Set the category to External link, unless it matches the portal link/url pattern (containing /community/), 
// in which case category gets set to whatever word follows /community/ in the path.
var category = "External link";
var matches = url.match(/\/community\/([^\/]+)/);
if (matches) {
category = matches[1];
}
alert(category);


// Get the link text
var linkText = $(this).text().trim();
alert(linkText);


// Alert the url, just for the order below's sake
alert(url);


// Track the click
//$(this).attr("onclick","_gaq.push(['_trackEvent'," + category + ",'click','" + linkText + "','" + url + "'])");
_gaq.push(['_trackEvent'," + category + ",'click','" + linkText + "','" + url + "'])


//return false;

});
});
</script>

</head>

<body>

<h1>Simulating links on Site</h1>

<ul>
<li><a href="http://inet.asdf.asdf.pvt/portal/server.pt/community/home/_articleviewer?ArticleId=s_011610">Read more</a></li>

</ul>

<script type="text/javascript">

var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-24902347-1']);
_gaq.push(['_trackPageview']);

(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();

</body>
</html>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T06:18:42+00:00Added an answer on May 24, 2026 at 6:18 am

    You’re passing too many parameters to the _gaq.push() function. It can only take 3 string arguments, but you’re passing 4.

    _gaq.push(['_trackEvent'," + category + ",'click','" + linkText + "','" + url + "'])
         //                  |    category   | action|     label        |    value   |
    

    Combine 2 of the arguments to be one, and it’ll work (or get rid of the “click” string for action, since its a waste). But, you’re also not passing the variable names; you’re just passing strings that are equivalent to the variable names. It looks like you’re actually trying to do something like this:

    _gaq.push(['_trackEvent', category,  linkText , url]);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I'm making a simple page using Google Maps API 3. My first. One marker
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am reading a book about Javascript and jQuery and using one of the
I am trying to render a haml file in a javascript response like so:
I want use html5's new tag to play a wav file (currently only supported

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.