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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T05:17:27+00:00 2026-05-26T05:17:27+00:00

How do we make a web page to execute a JavaScript function immediately after

  • 0

How do we make a web page to execute a JavaScript function immediately after Google Analytics creates/updates all its cookies and the page DOM is loaded.

Can it be done with jQuery? How?

This function gets information from the GA cookies. I’ve tried executing the function when the page DOM is loaded, but sometimes GA has not created it’s cookies yet.

  • 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-26T05:17:28+00:00Added an answer on May 26, 2026 at 5:17 am

    There are 2 elements here: First, DOM ready with jQuery. That’s easy:

    $(document).ready(function(){
    //do something
    });
    

    The way to ensure that your function executes after Google Analytics has created its cookies (once it had implicitly executed initData()) is to pass the function within the _gaq array queue so that it gets executed after the _trackPageview call.

    For example:

    _gaq.push(["_trackPageview"]);
    _gaq.push(function(){
        //when this executes, the google analytics cookies definitely exist
    });
    

    So, you could put the following anywhere on the page below _gaq.push(["_trackPageview"]) (or after any _gaq call that initiates the cookies; most commonly, _trackPageview, _trackEvent, and _setCustomVar.

    _gaq.push(function(){
        //do something
    });
    

    Now to ensure that the function both executes after DOM Ready and that initData() is implicitly called, you can either do this:

    _gaq.push(function(){
        $(document).ready(function(){
            //do something
        });
    });
    

    Or:

    $(document).ready(function(){
        _gaq.push(function(){
            //do something
       });
    });
    

    They both do what you’re looking for, though it sounds like the first one better fits your mental model of what you’re trying to accomplish.

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

Sidebar

Related Questions

I'm trying to make a web scraper that will parse a web-page of publications
How would you make a button in cocoa when clicked open a web page?
I use System.Web.Services.WebMethodAttribute to make a public static method of an ASP.NET page callable
When using Visual Studio's built in web server, every time I make a page
I need to call a web page that has javascript. At the bottom of
I have got a list of many web page URLs.. and all of them
I'd like to be able to make the JavaScript I've got in a web
I whant to make a web interface on a server that will manage a
There is a web page with place holder (a normal div). Via ajax calls
I'm having some trouble figuring out how to make the page load architecture of

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.