1

I'd like to track how many people hit my website that might be logged into LinkedIn. Depending on the results, I might add an interactive LinkedIn section using their API.

I already have the Javascript logic to detect if they're logged in. My question is what is the best approach to log this result? Can Google Analytics do it with a custom variable or event detection?

I'd love to report on something like, "10,000 visits to my website, of which X number of visitors were logged into LinkedIn".

Any help would be appreciated!

scottystang
  • 351
  • 6
  • 22

1 Answers1

1

I believe Google Analytics Custom Tracking Variables would do the trick. Something along the lines of:

_gaq.push(['_setCustomVar',
  1,              // variable slot
  'LinkedInUser', // variable
  'true',         // value
  1               // variable scope, 1=visitor
]);
_gaq.push(['_trackPageview']);

For custom variables (not that is this is a user-triggered event after the initial GA page load logic, a call to _trackPageview is needed to push the data back to GA), or:

_gaq.push(['_trackEvent',
  'PageView',
  'LinkedIn'
]);

For custom events. Just pop something similar to that into your JS routine that checks for authed LinkedIn users.

Unpossible
  • 10,607
  • 22
  • 75
  • 113
  • 2
    please note that this code does not actually send a request to GA, it just sets the custom variable. After setting this, you will have to pop a "trigger" .push() call to actually send it to GA (_trackEvent or _trackPageview). Ideally you will want to place this after the _gaq object is created, but before the _trackPageview call. – CrayonViolent May 29 '12 at 18:48
  • Would this do it? _gaq.push(['_setCustomVar', 1, 'Social Sites', 'LinkedIn', 1], ['_trackPageview','/social-sites/linkedin']); – scottystang May 29 '12 at 19:17
  • @CrayonViolent yes, thanks for the comment, have added additional code to answer. – Unpossible May 29 '12 at 23:52
  • Is this something I can test from my localhost or will it only populate GA if it's on my live site? – scottystang May 30 '12 at 14:09
  • [Looks that way](http://stackoverflow.com/questions/4375447/can-you-test-google-analytics-on-a-localhost-address) – Unpossible May 30 '12 at 14:40