wordpress - Why Google Analytics doesn't track all my events with _setcustomvar? -


i'm using following code

_gaq.push(['_setcustomvar',1,'logged-in','administrator',1],['_trackpageview']);

to track logged-in user levels on site (running wordpress).

now problem in last month had around 100 new registrations, google analytics shows me 65 registered users active on site.

is error in interpreting results or doing wrong?

preamble
google analytics(ga), it's impossible hits registred. not ga specific problem. analytics tool can affected.

imagine instance, user gets connection broken while registring on wp site. chances javascript code won't executed. new user registred hopefully, ga won't notified.


workaround
workaround tied notification of ga registration process right on server side:

step 1: register php function user_register hook.

 add_action('user_register', 'myplugin_registration_save'); function myplugin_registration_save($user_id) {     // ga notified here ... } 

step 2: inside registred function notify ga of new user registration.
here comes php-ga. it's ga client written in php. can implement every parameter , tracking feature of original ga javascript client. call track ga custom vars.

here sample code php-ga site:

use unitedprototype\googleanalytics;  // initilize ga tracker $tracker = new googleanalytics\tracker('ua-12345678-9', 'example.com');  // assemble visitor information // (could unserialized database) $visitor = new googleanalytics\visitor(); $visitor->setipaddress($_server['remote_addr']); $visitor->setuseragent($_server['http_user_agent']); $visitor->setscreenresolution('1024x768');  // assemble session information // (could unserialized php session) $session = new googleanalytics\session();  // assemble page information $page = new googleanalytics\page('/page.html'); $page->settitle('my page');  // track page view $tracker->trackpageview($page, $session, $visitor); 


there more
if implement workaround, may not able notify ga sucessfully. if ga server experiment heavy load instance, notification may lost.

i advice use both system notification : ga javascript client and ga php client.

assign them 2 distinct events 'js-new-user-registred' , 'php-new-user-registred'. 2 registred events improve quality of analytic data. improve new registrations notification rate too.

always keep in mind approach may not 100% accurate. example, on client side ga.js file may blocked (firewall etc). @ same time, php client may not able notify succesfully ga. results new registration not tracked.


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -