I've been asked for "development/editing" time for pages analytics to be made available.

Is this possible? If so, how?

  • do you mean analytics on how long it takes each page to load, i.e. performance analytics?
    – schnippy
    Feb 11, 2013 at 2:57
  • No, sorry @schnippy What the client is after is the duration the page/not was being edited...
    – user12885
    Feb 11, 2013 at 3:29
  • 1
    wait- what? ;) the goal is to track the amount of time an admin user was editing a page? so, track to google analytics the time from when the admin user opened the page to edit it to when they saved it? I've got an idea how to do this but just want to confirm thats the target scenario because, wow.
    – schnippy
    Feb 12, 2013 at 2:26
  • haha. yeah i know. pretty ridiculous, isn't it? But yes, that's what the client wants :( @schnippy
    – user12885
    Feb 12, 2013 at 2:45
  • @schnippy +1 for the great comment. I honestly could not stop laughing :)
    – 9ee1
    Feb 13, 2013 at 2:46

1 Answer 1


Ok - you want to use Google Analytics custom variables for this and a bit of javascript (though will try and make this as Drupaly as possible). For the timer, you can write javascript/jQuery code to start a timer on the window.load() event and then attach it to the submit button on your particular form. Number of examples of javascript timers, I found this example that looked promising.

Key thing to get this data to your google analytics account is to add a google analytics push event (see documentation above) so your code would look something like this (rough psuedo code)

$(document).ready(function() {

   function StartTimer() { some timer function ... }

   function StopTimer() { some timer stop function ... return $time; } 


       $timeValue = StopTimer();
          1, // This custom var is set to slot #1.  Required parameter.
          'Editor Time', // Category Name. Required Parameter
          $timeValue,  // This value of the custom variable.  Required.
          3  // Sets the scope to page-level.  Optional parameter.


Finally, you need to attach your javascript to your form (the drupaly part). I use this quick code snippet (from switchbackcms) as a good way to avoid losing the javascript if the user reloads the form:

function hook_form_alter(&$form, $form_state, $form_id){
  if($form_id == 'form_in_question'){
     $form['some_element']['#after_build'] = array('_load_my_javascript);

function _load_my_javascript($element){
      drupal_get_path('module', 'my_module') 
        . '/track_editors.js');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.