Page 1 of 2 12 LastLast
Results 1 to 10 of 11

Thread: Google Analytics for Ajax Tabs Content script

  1. #1
    Join Date
    Dec 2009
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation Google Analytics for Ajax Tabs Content script

    1) Script Title: Ajax Tabs Content script v2.2

    2) Script URL (on DD): http://www.dynamicdrive.com/dynamici...axtabscontent/
    http://www.dynamicdrive.com/dynamici...bs/ajaxtabs.js

    3) Describe problem: The Google Analytics does not record ajaxtabscontent activity.
    Does someone knows to change ajaxtabs.js to active it for Google Analytics records?
    Do I need to change also Google Analytics supported js code?

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    29,076
    Thanks
    44
    Thanked 3,216 Times in 3,178 Posts
    Blog Entries
    12

    Default

    I'd try - Let's say your tabs instance is countries, ex:

    Code:
    var countries=new ddajaxtabs("countrytabs", "countrydivcontainer")
    countries.setpersist(true)
    countries.setselectedClassTarget("link") //"link" or "linkparent"
    countries.init()
    Add this code right below that:

    Code:
    countries.onajaxpageload = function(){
    pageTracker._initData();
    pageTracker._trackPageview();
    };
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    Dec 2009
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Then probably it must look:

    countries.onajaxpageload=function(pageurl){
    pageTracker._initData();
    pageTracker._trackPageview();}

    http://www.dynamicdrive.com/dynamicindex17/ajaxtabscontent/ajaxtabs_suppliment2.htm

  4. #4
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    29,076
    Thanks
    44
    Thanked 3,216 Times in 3,178 Posts
    Blog Entries
    12

    Default

    The page's URL parameter is passed to the onajaxpageload function regardless of whether or not it is specified as the function sole argument, which is what it is. If not used by the code in the onajaxpageload function it need not be given a token, which is only required for convenience if you are planning on using it. It will always be available within the onajaxpageload function as:

    Code:
    arguments[0]
    But since it isn't required for:

    Code:
    pageTracker._initData();
    pageTracker._trackPageview();
    to do its work, it may be omitted.

    The only possible problem is if:

    Code:
    pageTracker._initData();
    pageTracker._trackPageview();
    doesn't properly initialize the newly imported content for some reason. However, it is very likely that it will.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  5. #5
    Join Date
    Dec 2009
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation

    Thanks jscheuer1 for advice, but code does not work for me. The Google Analytics does not record ajaxtabscontent activity.

    Before </head> I have:
    Code:
    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"));
    my axtabscontent:
    Code:
    var countries=new ddajaxtabs("countrytabs", "countrydivcontainer")
    countries.setpersist(true)
    countries.setselectedClassTarget("link")
    countries.init()
    countries.onajaxpageload=function(){
      pageTracker._initData();
      pageTracker._trackPageview();
    }
    countries.onajaxpageload=function(pageurl){
      jQuery(document).ready(function($) {
        $('a[rel*=facebox]').facebox() 
      })
    pageTracker._initData();
    pageTracker._trackPageview();
    }
    and before </body>
    Code:
    try{
    var pageTracker = _gat._getTracker("UA-XXXXXXXX-X");
    pageTracker._trackPageview();
    } catch(err) {}
    Do you have some advice? Maybe my JavaScript has some mistakes?

  6. #6
    Join Date
    Dec 2009
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    some solution?

  7. #7
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    29,076
    Thanks
    44
    Thanked 3,216 Times in 3,178 Posts
    Blog Entries
    12

    Default

    Sorry, I had lost track of this thread. Yes, your code is at least odd, perhaps ultimately doing nothing on tab load. You may only have one countries.onajaxpageload function, in your case, the second one overwrites the first, so:

    Code:
    countries.onajaxpageload=function(){
      pageTracker._initData();
      pageTracker._trackPageview();
    }
    never happens. This one:

    Code:
    countries.onajaxpageload=function(pageurl){
      jQuery(document).ready(function($) {
        $('a[rel*=facebox]').facebox() 
      })
    pageTracker._initData();
    pageTracker._trackPageview();
    }
    overwrites it. But the jQuery(document).ready event has already passed, so I doubt that part does anything, it may even throw an error and prevent execution of:

    Code:
    pageTracker._initData();
    pageTracker._trackPageview();
    So, I'd just forget about facebox, at least until we can see if we can get the Google Analytics working. I took my init for that from one I found on a page on Dynamic Drive, but yours looks different, so let's try that. Replace both of your countries.onajaxpageload functions with:

    Code:
    countries.onajaxpageload=function(){
    try{
    var pageTracker = _gat._getTracker("UA-XXXXXXXX-X");
    pageTracker._trackPageview();
    } catch(err) {}
    };
    Make sure the live page is updated and not showing in the browser. Clear the browser's cache, then navigate to the live page to see what the effect has been.

    We still have a potential problem, one I'm not sure if there is anything we can do about. Either or both of these functions:

    _gat._getTracker("UA-XXXXXXXX-X")

    and:

    instance._trackPageview()

    May only be allowed to run once. If it's just _gat._getTracker("UA-XXXXXXXX-X") we could remove that line and try again with just:

    Code:
    countries.onajaxpageload=function(){
    try{
    pageTracker._trackPageview();
    } catch(err) {}
    };
    If the instance._trackPageview() can only be run once, there isn't a lot we can do. Perhaps there is a forum where Google Analytics is discussed. If so, they may have a solution.

    Another thing to try though would be using only:

    Code:
    countries.onajaxpageload=function(){
    try{
      pageTracker._initData();
      pageTracker._trackPageview();
    } catch(err) {}
    };
    But it could be possible that the Google Analytics code is not flexible enough to be applied to AJAX imported content.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  8. #8
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    29,076
    Thanks
    44
    Thanked 3,216 Times in 3,178 Posts
    Blog Entries
    12

    Default

    Hmm, I'm looking into this more. And now I see that we should be able to track any event:

    http://code.google.com/apis/analytic...ckerGuide.html

    But what is it that you want to track? Do you want to track when a tab is clicked? Or do you want to track when things happen inside the imported content?
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  9. #9
    Join Date
    Dec 2009
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation Google Analytics track ajax loading request

    Quote Originally Posted by jscheuer1 View Post
    Do you want to track when a tab is clicked? Or do you want to track when things happen inside the imported content?
    I would like to track ajax content loading requests.
    jscheuer1, do you have some solution?

  10. #10
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    29,076
    Thanks
    44
    Thanked 3,216 Times in 3,178 Posts
    Blog Entries
    12

    Default

    I think I know what you are getting at, but after so much time it will take some research of the link from my last post. So, just to be clear, as your answer was a little ambiguous:

    1. Do you want to track when a tab is clicked?

      OR:

    2. Do you want to track the clicks that occur within the content that is imported when a tab is clicked after said content has been imported?


    Please respond with either the number 1 or the number 2, or with a detailed explanation of what you want to track (that isn't already being tracked) if neither of the above represents it correctly. I think you are going for number 2. But I'm not 100% sure yet. Let me know.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •