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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T17:02:35+00:00 2026-05-23T17:02:35+00:00

On a single page webapp, I’ve implemented the google async tracker. I created a

  • 0

On a single page webapp, I’ve implemented the google async tracker. I created a class to be able to make some simple calls to be able to track users across the site:

var GoogleAnalytics = {
    config : {
        'account':'UA-XXXXXXXX-X'
    },
    init : function(){
        var _gaq = _gaq || [];
        this.tracker = _gaq;
        _gaq.push(['_setAccount',this.config.account]);
        (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);
          })();
    },
    doAsyncRequest : function(arr){
        if(!this.tracker) this.init();
        this.tracker.push(arr);
    },
    trackPageView : function(url){
        var args = ['_trackPageview'];
        if(url) args.push(url);
        this.doAsyncRequest(args);
    },
    trackEvent : function(category,action,label,value){
        var args = ['_trackEvent',category,action];
        if(label) args.push(label);
        if(value) args.push(value);
        this.doAsyncRequest(args);
    },
    trackCustom : function(index,name,value,scope){
        var args = ['_setCustomVar',index,name,value];
        if(scope) args.push(scope);
        this.doAsyncRequest(args);
    }
}

When the app is loaded, I create an instance of the above like so:

var that = this;
require(['js/plugins/GoogleAnalytics'],function(ga){ that.ga = GoogleAnalytics; });

it uses require.js to load in the above script, and assign this.ga to it.

Then, when trying to track a page view, I use this:

var that = this
$.each(payload.events,function(index,event){
    if(event.eventType == 'page'){
        var pagePath = event.currentURL.replace(/^(https?:\/\/[^\/]+)/i,'');
        that.ga.trackPageView(pagePath);
    } else {
        that.ga.trackEvent(event.eventType,event.elementClass);
    }
});

payload.events just contains an array of events. an event looks something like this for a page view: {'eventType':'page','currentURL':'http://www.testurl.com/#!/testing/test/test'}

This all gets to google ok, but in analytics, it tracks a page view as a unique page visit, and doesn’t track across the users’ visit. So my analytics are somewhat useless, as it looks like I have WAY more visits than I really do, and a ridiculous bounce rate.

Is there something I’m missing that would fix this and make it track page views like a normal analytics install?

  • 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-23T17:02:36+00:00Added an answer on May 23, 2026 at 5:02 pm

    Frankie got this one right in my comments, I believe the issue was with require.js making a new scope and something breaking there.

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

Sidebar

Related Questions

I created a single page (with code behind .vb) and created Public intFileID As
In my current project I'm getting some html templates (for a single page interface
I'm thinking about this since a while: I'm build a single-page webapp with ExtJS
We have an single-page web app that displays emails. Some of the emails we're
I'm developing a website. I'm using a single-page web-app style, so all of the
Basically I have a single page on my site that I want any php
If I have a single page with many forms of existing records: index.html.haml -
I have an image upload page (single page). When submitted it check filesize and
I have a struts2 application with a single page that may show one of
What is the best way to authorize all users to one single page in

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.