views:

16

answers:

1

I'm trying to track how often a Poll content type is answered as a block in Drupal when it's embedded on a number of pages as a block. For example, if 5 users answer the poll on page A, and six users answer on page B, I need to know those breakdowns, but not their specific answers.

I'd planned to simply look in Google Analytics for the number of times users had taken the path from Page A -> Poll Page, but answering the Poll actually leaves the user on the same page, so I'm stumped how to do it. Any suggestions?

+2  A: 

For performance, using google analytics is not a bad idea. You can attach a JavaScript event to the submit button of the form, and send the info to GA, about the poll, before the form submits.

An alternative solution, would be to track it in Drupal. Here you could add a submit handler to the form, and save the url it was posted from. You would need to add the submit handler with hook_form_alter

JavaScript is not that hard, you got jQuery loaded, so something like this should do.

$("#poll-form #edit-submit").click(function(){
  if ($(this).hasClass('ready')) {
    return true;
  }
  // Do your thing with GA, add a callback function when you have posted to google:
  function callback() {
    $("#poll-form #edit-submit").addClass('ready').click();
  }

});

Look up the GA api for what you need to do, it depends on which version you use.

googletorp
Thanks! Any advice on where I could get started figuring out how to add a JavaScript event to the submit button?
Michael Morisy