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 8429617
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T05:23:12+00:00 2026-06-10T05:23:12+00:00

On all my site pages I have the google analytics async code setup as

  • 0

On all my site pages I have the google analytics async code setup as follows just before the closing head tag….

<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-XXXXXX-X']);
_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);
})();</script>

Then on my checkout pages I am trying to use event tracking to report the time the user spent on the various pages as the value for google analytics events.

I am doing this by making use of the jQuery.ready function to record the ‘start’ time and add event handlers to the submit buttons that take the user to the next step in the checkout. This code is in a external file, common.js and is as follows…

        $(document).ready(function() {
        recordStartTime();
        if ($("#checkoutPage1").length) 
        {   
            if ($("#customerDetailsForm").length) 
            {   
            // Time spent
                $('.customerDetailsSubmitButton').click(function() {
                time = durationWholeSeconds();
                _gaq.push(['_trackEvent', 'Checkout', 'Timing', 'CustomerDetailsPage', time]);
                return true;
                });
            }
        }

I have similar sections of code for the other steps in jQuery.ready, #checkoutPage1, #checkoutPage2, #checkoutPage3 etc.

When I test this code on my browser (Chrome) all works as expected and using the ga.debug plugin I can see the _trackEvent parameters being sent to google analytics.

My problem seems to be that this does not always seem to work in the wild. On my live site I see intermittent events coming through. Given I know pretty accurately how many ‘sales’ I have the events that should be expected in GA do not match. Often some of the latter events in the checkout steps report without the earlier ones being recorded.

My question is basically can I use the jQuery.ready function to add the event handlers and the tracking code where needed? Is there another issue I am not spotting?

  • 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-10T05:23:14+00:00Added an answer on June 10, 2026 at 5:23 am

    You can use jQuery.ready, but you have to keep in mind that sometimes jQuery.ready will not fire. Sometimes users will navigate away before the DOM is ready.

    You didn’t post your functions recordStartTime and durationWholeSeconds. If they raise an exception on a browser for some reason than that session won’t fire events. Maybe you should make sure they are shielded by try catch blocks to fire the Event even if they fail.

    I would also advise you to use $('.customerDetailsSubmitButton').mousedown instead of click. mousedown fires first and here timing is essential. If the browser redirects before the Event goes through there’s a chance it will be canceled and never reach GA. In our tests using mousedown we see almost twice the hits than using click.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im using 960gs adaptive CSS in all the pages of my site. I have
I have a site that leverages both Google Analytics and Google Maps. Both of
I have a Drupal site with pages indexed by a Google Mini search appliance.
I have a site which uses overlay pages, all was working fine until I
I have installed the below google tracking code in my site var _gaq =
I have a site that uses google analytics and is that uses a number
We have an older site which still uses the ancient gat Analytics tracking code
i have a search page in my site, where user can search all the
Basically all pages on this site I am building cannot be accessed when the
I am using the following .htaccess rule to redirect all pages of my site

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.