CardinalPath / gas

Google Analytics on Steroids. A Google Analytics implementation with more power features.
Other
593 stars 78 forks source link

Switch links with onclick attribute to mousedown for Multidomain #69

Open googleanalyticsresoneo opened 10 years ago

googleanalyticsresoneo commented 10 years ago

By default we have _gas.push(['_gasMultiDomain', 'click']);

But when one of the links already has a function binded to the 'onclick' gas should try to use 'mousedown' as an alternative handler so that, for example, the link isn't opened twice

I had the case with 'onclick' doing a window.open in JS in a new window and gas opening in the current window, resulting in 2 page views, one in a new visit and the other one in the current visit....

It shouldn't be needed to change the behavior for all the links in the page, but be careful to change the default behavior when it's at risk because an existing onclick code.

What do you think ?

tomfuertes commented 10 years ago

Agree that this could be more gracefully handled but don't want to change as it would:

  1. cause lots of if statements/branches making the src/plugins/multidomain.js file unreadable
  2. more than likely be backwards incompatible for people upgrading
  3. negate the base use case for people who don't already have click handlers (which is much greater than the edge)

For now maybe we should just update the docs to make the standard _gasMultiDomain value mousedown instead of click? Happy to accept the PR.

googleanalyticsresoneo commented 10 years ago

At least there should be more comments in the code or in the documentation on the benefits / risks of each methods But it's very difficult to be sure that no link on a site is using an onclick handler, then having a safe solution would be way better. Source code being readable is a matter of comments and structure...shouldn't be an obstacle to stability and safety.