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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T20:17:14+00:00 2026-05-29T20:17:14+00:00

I made a helper for my javascript in order to track some ajax events,

  • 0

I made a helper for my javascript in order to track some ajax events, here’s a short version of what it’s set up to be

analytics:{
        active: false,
        gaq:  null,
        init: function(gaq){
            this.active = true;
            this.gaq = gaq;
            $('a[href^=\"http://\"]').live('click', function() {
                helper.analytics.trackPageview('/outgoing/' + $(this).attr('href'));
                return true;
            });
        },
        trackPageview: function(page){
            if(this.active === false){
                return;
            }
            this.gaq.push(['_trackPageview',page]);
        }
    },

And I have the common google analytics setup

<script type="text/javascript">
  var _gaq = _gaq || []; _gaq.push(['_setAccount', 'UA-xxxxxxxx-1']); 
   _gaq.push(['_setDomainName', '.example.com']);
   _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);
  })();
  $(document).ready( function() {
    helper.analytics.init(_gaq);
  });
</script>

However in the console logging _gaq results in an object. logging helper.analytics.gaq results in an array, whith new pageviews appended, but the pageview is not being tracked in google analytics.
Why isn’t _gaq being passed to the helper by reference?

  • 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-29T20:17:14+00:00Added an answer on May 29, 2026 at 8:17 pm

    When creating the script tag, the ga snippet sets the async attribute to true. Therefore, it’ll load independently from the body. You’ll need to bind an event handler to the ga script tag’s onload event. Something like so:

    (function() {
     var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
    
     ga.onload = function(){
      herlper.analytics.init(_gaq);
     };
    
     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);
    })();
    

    I’ve not tested this, but I think it might work.

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

Sidebar

Related Questions

here are two little helper methods I have made for downloading files. I have
I've made a helper, that should output some data from my database in the
I have made some helper functions that run a simulation using a lot of
I made a Java Applet with some Standard GUI Components on it. I used
I made a discovery some time back. Just follow these steps: Create a .doc/.xls/.ppt
I am trying to make Http connections made by C# HttpClient helper class reusable.
I made a web app that loads images using jquery, ajax and json. I
I want to override the Active Record class (some functions of it at least).
i'm having a hard time dealing with MVC Ajax helper and trying to refresh
I've made a helper public static class UrlHelperExtension { public static string GetContent(this UrlHelper

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.