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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T07:25:02+00:00 2026-06-12T07:25:02+00:00

In the following code I am attempting to:- Define google analytics on the page

  • 0

In the following code I am attempting to:-

  • Define google analytics on the page
  • Add a jquery click event if the page has a certain query string and characters in the domain
  • The click event invokes a google analytics tracking event
  • I also have code checking for query strings and values within a domain

What is not working:-

  • The third item, which is invoking google analytics tracking event, I seem to be hitting it but nothing is being returned into my GA account.

What I have tried:-

  • I have triple checked that information for _gaq_.push is correctly linking to correct account.
  • Used firebug and IE9 developer tools to follow javascript and analyze what is going on. This is how I know I am hitting the event tracking when my scenarios are true.
  • Tried in a isolated environment like jsfiddle, will not give link to its because I can’t actually give company information out. It doesn’t work in js fiddle. ( mainly because jsfiddle can’t authenticate with my ga account (domains are different).
  • I have tried in an isolated file within my relevant domain still no luck.

    var _gaq = _gaq || [];
    _gaq.push(['_setAccount', 'UA-XXXXX-X']);
    _gaq.push(['_setDomainName', 'mydomain.co.uk']);
    _gaq.push(['_setAllowLinker', true]);
    _gaq.push(['_setSiteSpeedSampleRate', 100]); // this is a new line, allowing us to see how fast all pages load
    _gaq.push(['_trackPageview']); // we’ve moved this line down, as ‘setdomain’ (etc) should appear before it
    
    (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 () {
        var querystring = (function (a) {
            if (a == "") return {};
            var b = {};
            for (var i = 0; i < a.length; ++i) {
                var p = a[i].split('=');
                if (p.length != 2) continue;
                b[p[0]] = decodeURIComponent(p[1].replace(/\+/g, " "));
            }
            return b;
        })(window.location.search.substr(1).split('&'));
        if (querystring["utm_expid"] != null) {
            $('a').click(function () {
                if ($(this).attr("href") != 'undefined' && $(this).attr("href") != null) {
                    if ($(this).attr("href").toLowerCase().indexOf("keyword") >= 0 && $(this).attr("href").toLowerCase().indexOf("keyword2") >= 0) {
                        _gaq.push(['_trackEvent', 'eventCategories', 'eventAction', 'eventLabel']);
                    } else if (($(this).attr("href").toLowerCase().indexOf("keyword") >= 0 && $(this).attr("href").toLowerCase().indexOf("keyword2") >= 0 && $(this).attr("href").toLowerCase().indexOf("keyword3") >= 0) || ($(this).attr("href").toLowerCase().indexOf("keyword4") >= 0)) {
                        _gaq.push(['_trackEvent', 'eventCategories', 'eventAction', 'eventLabel']);
                    }
                }
            });
        }
    });
    
  • 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-06-12T07:25:03+00:00Added an answer on June 12, 2026 at 7:25 am

    Google Analytics _trackEvent (and _trackPageview, etc) work by making a tracking pixel request from the analytics server. If the click results in loading a new page to the same window before the tracking request has completed, you can end up with missing data, or only tracking some of the data.

    The following code adds a slight delay before following the link:

    var delayLink = function(e, url) {
      e.preventDefault();
      setTimeout(function(){location.href = url}, 150);
    };
    
    if (querystring["utm_expid"] != null) {
        $('a').click(function (e) {
            if ($(this).attr("href") != 'undefined' && $(this).attr("href") != null) {
                if ($(this).attr("href").toLowerCase().indexOf("keyword") >= 0 && $(this).attr("href").toLowerCase().indexOf("keyword2") >= 0) {
                    _gaq.push(['_trackEvent', 'eventCategories', 'eventAction', 'eventLabel']);
                    if (this.target != '_blank') delayLink(e, this.href);
                } else if (($(this).attr("href").toLowerCase().indexOf("keyword") >= 0 && $(this).attr("href").toLowerCase().indexOf("keyword2") >= 0 && $(this).attr("href").toLowerCase().indexOf("keyword3") >= 0) || ($(this).attr("href").toLowerCase().indexOf("keyword4") >= 0)) {
                    _gaq.push(['_trackEvent', 'eventCategories', 'eventAction', 'eventLabel']);
                if (this.target != '_blank') delayLink(e, this.href);
                }
        }
        });
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm learning jQuery, and am attempting to understand the following code structure. if(jQuery) (function($){
I am attempting to use the following code to search a database using words
Following code is a pretty simple and complete JQuery Dialog. Everything works. Problem is
following code doesn't work with input: 2 7 add Elly 0888424242 add Elly 0883666666
The following code used to function without attempting to render a new template with
I'm attempting a fetch request with the following code: NSPredicate *predicate = [NSPredicate predicateWithFormat:@dateModified
The following code throws an error on the CreateIfNotExist method call. I am attempting
I am trying attempting to refactor the following code: public static void SaveSplitbar(RadSplitBar splitBar)
I have the following code that is attempting to start each of the commands
I am attempting to create the following code through the use of CodeDom: public

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.