Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Track optionally downloads and outlinks for middle clicks and open context menu #8068

Merged
merged 2 commits into from Jun 16, 2015

Conversation

tsteur
Copy link
Member

@tsteur tsteur commented Jun 9, 2015

fixes #5287 as discussed in the issue.

There was already an opt-in flag called enabled to track middle clicks (I think it did not work properly BTW). I reused this one to also track "opened context menu". To use this new feature use tracker.enableLinkTracking(true) or _paq.push(['enableLinkTracking', true]);

We can later change the default from enabled=false to enabled=true.

  • As mentioned "middle clicks" where tracked before when enabled=true was set. I kinda doubt it worked since it did not consider some browser incompatibilities but there's a chance it did work. Anyway, "middle clicks" should be now tracked more accurately.
  • In newer browsers we will track if someone opens the context menu (right click, or ctrl+left click on Mac, metaKey+left click on Windows, ...)
  • In some browsers we also track if someone opens it directly in a new window (ctrl+ left click on Windows, metaKey+left click on Mac). It should work at least in Firefox and Chrome. It didn't work in IE10

I tested in many browsers (on Saucelabs) and on some phones and it should work but one can never tell re different browser behaviour. It should be pretty safe to merge though.

}
} else if (evt.type === 'mouseup') {
if (button === lastButton && target === lastTarget) {
} else if (event.type === 'contextmenu') {
processClick(target);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's important to know that when the contextmenu event is triggered, a click event is not triggered. At least in all the browsers that I tested. This is important as we would otherwise track a click multiple times. There is a certain risk if a browser changes this behaviour or if a browser is buggy that we track multiple times.

@tsteur tsteur added not-in-changelog For issues or pull requests that should not be included in our release changelog on matomo.org. Needs Review PRs that need a code review labels Jun 9, 2015
@tsteur tsteur added this to the 2.14.0 milestone Jun 9, 2015
@tsteur
Copy link
Member Author

tsteur commented Jun 15, 2015

In case someone is wondering how I tested on Saucelabs:

First of all: It was a manual test, not an automated test. What I did was to create a standalone, plain html file and uploaded it on a server. That html file contained only the piwik.js logic and a link. Then I logged in on Saucelabs and tested all possible combinations (left click, right click, metaKey + left / right click , ctrl + left / right click) and made sure that always the correct events are triggered and that we do not track anything twice. Eg it would be wrong if we'd track 2 clicks ('click' and 'contextmenu' event) if someone opens the context menu via ctrl + click. Tested on Linux, Mac, Windows, iOS, Android various browsers including IE6 and IE8

@diosmosis
Copy link
Member

Looks ok to me, will merge after some manual testing.

diosmosis added a commit that referenced this pull request Jun 16, 2015
Fixes #5287, track optionally downloads and outlinks for middle clicks, opening context menus and ctrl/command clicks.
@diosmosis diosmosis merged commit 57a6102 into master Jun 16, 2015
@diosmosis diosmosis deleted the 5287 branch June 16, 2015 00:48
mattab pushed a commit to matomo-org/developer-documentation that referenced this pull request Jun 26, 2015
@mattab mattab mentioned this pull request Jun 26, 2015
8 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs Review PRs that need a code review not-in-changelog For issues or pull requests that should not be included in our release changelog on matomo.org.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants