Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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.
Comment | File | Size | Author |
---|---|---|---|
#3 | google_analytics_et-single_event-1870694-0.patch | 1.04 KB | dbassendine |
#1 | google_analytics_et-single_event-1870694-0.patch | 1.04 KB | dbassendine |
Comments
Comment #1
dbassendine CreditAttribution: dbassendine commentedI'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:
Let me know what you think! David
Comment #2
frobI 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.
Comment #3
dbassendine CreditAttribution: dbassendine commentedThat 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
Comment #4
frobComment #5
frobI ended up doing a completely different approach. But this is in now. Time for a new release don't you think?
Comment #7
frob