It would be useful to provide the option in the API to track an event only once, rather than every time the event is triggered. A use case for this is when tracking a flash video play. The mousedown event fires every time a visitor clicks the play, pause, adjust the controls etc., but we really only want to know if the object has been clicked once and ignore subsequent clicks.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

dbassendine’s picture

I've written a patch to do this, by adding a boolean option to the API called "once". If "once" is TRUE, then the js uses the one() method rather than bind(). The once option is optional, and the JS would default to bind() if it's not set. The tracker API would look like the following:

  array(
      'event' => 'mousedown', 
      'selector' => '.node-type-video .emvideo object',
      'once' => TRUE,
      'category' => 'Video',
      'action' => 'Play',
      'label' => '!currentPage',
      'value' => 0,
      'noninteraction' => TRUE,
    ),

Let me know what you think! David

frob’s picture

Version: 6.x-1.1 » 7.x-1.x-dev

I would prefer if it was in a options array rather than in the main array. That way as more options are add they are more manageable.


array(
      'event' => 'mousedown', 
      'selector' => '.node-type-video .emvideo object',
      'options' => array('once => TRUE),
      'category' => 'Video',
      'action' => 'Play',
      'label' => '!currentPage',
      'value' => 0,
      'noninteraction' => TRUE,
    ),

dbassendine’s picture

Version: 7.x-1.x-dev » 6.x-1.1
FileSize
1.04 KB

That sounds good, Frob.

For starters, here's a patch that uses the previous approach, and I'll update this to the "options" approach once I get a chance. It's currently against 6.x-1.1, unfortunately, since I'm building against a 6.x build for this work - but hopefully it can be transferred relatively quickly.

Here, I'm just using the configuration option to use either "bind" or "one" in jQuery to attach the event to the DOM element. Let me know how this looks for you in testing - I've tested and I'm using this to trigger an event on only the first click on a Youtube video.

Thanks, David

frob’s picture

Version: 6.x-1.1 » 7.x-1.x-dev
Assigned: dbassendine » Unassigned
frob’s picture

Component: Code » Miscellaneous
Issue summary: View changes

I ended up doing a completely different approach. But this is in now. Time for a new release don't you think?

  • frob committed a7074d2 on 7.x-1.x
    Issue #1870694 by dbassendine, frob: Option to track an event only once
    
frob’s picture

Status: Active » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.