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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T11:30:56+00:00 2026-05-13T11:30:56+00:00

So after a huge headache, I got my site to load its pages all

  • 0

So after a huge headache, I got my site to load its pages all via ajax. The reason being the client wanted it to flow exactly like their old flash site.. duh.

Anyway, everything was dandy, but then I added the google analytics trackers, and it wont load anymore!

So heres how I am doing the ajax:

$("li.home a").click (function() {       
    ajax_load("index.php",this);
    return false;
});
$("li.location a").click (function() {
    ajax_load("location.php",this);
    return false;
});

etc...

function ajax_load(page,element) {

    // deals with making an element active in left nav
    $('#mainnav').find('li.active').removeClass('active');
    $(element).parent().addClass('active');

    // empty the wrapper, then add new content with a fade effect
    $("#wrapper").empty();
    $("#wrapper").css({'display' : 'none'})
    $.ajax({
        type: "POST",
        url: page,
        success: function(msg){            
            $("#wrapper").append(msg);
            $("#wrapper").fadeIn();
        }
    });

    // set the page hash, so we can add these pages to favorites if wanted
    var strLen = page.length;
    page = page.slice(0,strLen-4);
    window.location.hash = page;
}

All the individual pages are php files.. and when they get loaded there is a check at the start of the file to see if its an ajax request. If it is.. it skips the header and navigation to just the content and then skips the footer. this allows it to work when javascript is disabled.

So, to get google analytics to work on ajax page loads I thought I could simply just stick the google tracking code within the area that gets loaded when it is an ajax request…

Well that doesnt work! Right now, the only page with the google anayltics tracking code is the floorplans page so you can see what is happening. Any pointers would be greatly appreciated!

heres the google tracking code im using:

    <script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
try {
var pageTracker = _gat._getTracker("UA-11737385-5");
pageTracker._trackPageview();
} catch(err) {}</script>

// UPDATE //

I believe this should do it, thank you Pekka!

    $.ajax({
    type: "POST",
    url: page,
    success: function(msg){            
        $("#wrapper").append(msg);
        $("#wrapper").fadeIn();
        pageTracker._trackPageview(page);
    }
  • 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-13T11:30:56+00:00Added an answer on May 13, 2026 at 11:30 am

    There is a function you can use, _trackPageview. See the Google Analytics manual:

    How do I track AJAX applications?

    With a typical HTML page, you can use the URL to differentiate between multiple pageviews. But in an AJAX application, a request to the server is made without changing the URL of the page, making it difficult to track.

    By calling the _trackPageview function, however, you can assign a page filename to any AJAX event. Typically, this is done as part of the onreadystatechange function, after the data has been returned and all updates to the page have been made.

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

Sidebar

Related Questions

I have huge amount of data locally, but don't want to load all to
I'm trying out ASP.NET MVC, but, after reading a huge tutorial, I'm slightly confused.
In my app after a while, there seems to be a huge issue. There
After deploying WCF server (svc) on my Server, I have got this message when
The problem is there are relationships which are so huge that after normalizing they
I am looking after a huge old C program and converting it to C++
After a huge MySQL blunder on a production server (my fault, and yes I
I'm getting a huge dataset from a client's internal API. It'll contain a bunch
I converted my huge IOS program to ARC using xcode auto conversion. After that
In my application, i have to read a huge amount of data. After i

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.