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

  • Home
  • SEARCH
  • 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 8925385
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T07:41:00+00:00 2026-06-15T07:41:00+00:00

I am using jquery to log clicks on anchors to google analytics. I have

  • 0

I am using jquery to log clicks on anchors to google analytics.

I have code like the following, that wires up the event:

$(document).delegate("a[rel='mylink']", "Click", function (e) {
//log to google analytics
console.log('tracking link');
_gaq.push(event);
e.preventDefault();         
});

The problem is that the href seems to be followed too quickly for this event to fire.

Is there a way to delay the following of the href until the event has been fired/completed?

I can see in the console that it gets as far as ‘tracking link’ but then it moves on before the google analytics push event completes.

Any advice appreciated.

  • 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-06-15T07:41:01+00:00Added an answer on June 15, 2026 at 7:41 am

    Google Analytics records data by making requests for a tracking pixel. As you’ve found, the request can be canceled when a new page is opened in the same window.

    Note: a delay is only necessary if the link being opened in the same window. I use some variation of the following for a click function:

    function(e) {
      _gaq.push(['_trackEvent', ...]);
      if (this.target != '_blank') {
        e.preventDefault();
        var url = this.href;
        setTimeout(function() {location.href = url}, 150);
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a login page using jQuery Mobile which contains the following code: <div
using jquery's .post i send do my php code an object that with var_dump
I have some jQuery code that doesn't work as expected. $('a[href^=http://]').not('[href^=http://mydomain.com], [href^=http://itunes.apple.com]').click(function (e) {
I'm using jquery-ui-map to create a Google Maps instance like this: $('#CHMap').gmap({ mapTypeControl :
I'm using jQuery's .on() event handler and it's only working when I use $(document)
Hi i am using this code: jQuery(document).ready(function(){ var number = 1; /////////////////////////////////////////////////// /* The
I'm creating a table with images using jQuery. My js code looks like this:
I'm trying to track clicks via Google Analytics that do not result in a
I have the following problem, I am using jquery mobile to build a webapp.
I am using jquery so that when the user clicks a link I get

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.