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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T10:57:41+00:00 2026-06-02T10:57:41+00:00

Although i’ve become quite well versed in jQuery unfortunately my Javascript is somewhat lacking

  • 0

Although i’ve become quite well versed in jQuery unfortunately my Javascript is somewhat lacking and I don’t have access to jQuery in this instance, so please no “use jQuery” answers.

Basically Google Analytics enables me to track social clicks as so:

_gaq.push(['_trackSocial', 'facebook', 'like', 'http://domain.com/somepage']); 

Now I have various links on my page like so:

<a href="#myfacebook#" track_social="facebook"><img src="facebook_button" /></a>
<a href="#mytwitter#" track_social="twitter"><img src="twitter_button" /></a>
<a href="#mygoogleplus#" track_social="googleplus"><img src="googleplus_button" /></a>
<a href="#mypinterest#" track_social="pinterest"><img src="pinterest_button" /></a>

Now what I would like is to track clicks on each of these and run the Google Analytics code demonstrated above. If I was using jQuery I would do something like this:

$('a[track_social]').click(function(){
    _gaq.push(['_trackSocial', $(this).attr('track_social'), 'click', $(this).attr('href')]);  
});

But as I said I don’t have access to jQuery so how would I do this using general Javascript?

It doesn’t necessarily have to use the “track_social” attribute, I could put something else in, but it can’t be unique ID’s for every single one as they’ll be appearing in multiple ways throughout the site and multiple times on various pages.

  • 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-02T10:57:51+00:00Added an answer on June 2, 2026 at 10:57 am

    That jQuery can be ported directly to native DOM APIs:

    Array.prototype.slice.call(
        document.querySelectorAll('a[track_social]')
    ).forEach(function(i) {
        i.addEventListener('click', function(e) {
            _gaq.push(['_trackSocial',
                e.target.getAttribute('track_social'),
                'click', e.target.href]);  
        }, false);
    });
    

    Please note that while this code is fully standards-compliant, it requires JavaScript 1.6 for forEach (supported in most major browsers, but only in IE 9+), and it requires addEventListener and querySelectorAll (supported in most major browsers, but only in IE 8+). You could add to this solution if you wanted wider browser support.


    Supplementary code #1:

    var n = document.querySelectorAll('a[track_social]');
    for (var i = 0; i < n.length; i++)
        n[i].addEventListener('click', function(e) {
            _gaq.push(['_trackSocial',
                e.target.getAttribute('track_social'),
                'click', e.target.href]);  
        }, false);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Although somewhat related to this question , I have what I think is a
Although I don't have an iPhone to test this out, my colleague told me
Although I have read the similar questions, this problem seems to be the exact
Although I have some experience in Android development, I don't have a lot of
Although this question fancies PostgreSQL, it is still a general DB question. I have
Although some questions similar to this one have been asked before, this one is
Although I'm specifically interested in web application information, I would also be somewhat curious
Although I do understand the serious implications of playing with this function (or at
Although ASP.NET MVC seems to have all the hype these days, WebForms are still
Although I grasp the concept of Bitwise Operators, I can't say that I have

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.