-
Notifications
You must be signed in to change notification settings - Fork 52
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
Honor target attribute for outbound link tracking #21
base: master
Are you sure you want to change the base?
Conversation
thanks for the contribution @Joelius300! i've extended your trial for couple more weeks to give you more time to figure out your credit card plus allows you to test whether this works the way it should |
Thank you very much! I'm now doing a bit of testing. I've setup a very simple application with webpack, html and typescript to test this feature. Repo and Plausible Dashboard. I didn't setup GH pages, I'm just using the domain because I have control over it (I'm testing with I will post my findings below. |
Tested with Firefox 94 and Chromium 94 on Linux Manjaro (Arch) 64-bit: I don't have a setup to verify that Good
|
648afe7
to
4d289d2
Compare
I think I'm done with this PR for now. I'm using the current state in Joelius300/werewolf-guide and it seems to work fine. The fix is complete as far as I can tell:
However the PR is not complete yet:
When the PR is done, the disclaimer in the main plausible docs can be revisited (removed?). Let me know if you'd like me to change anything, have questions or would like to help me with the missing pieces. I also enabled edits by maintainer so you should be able to directly commit to this PR if you want to. I'm happy to continue with this PR when you have time for it :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks good to me. Had one question. And I think indeed adding the tests you mentioned would be very useful
typeof process !== 'undefined' && | ||
process && | ||
process.env.NODE_ENV === 'test' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What are these for exactly? I assume it's to avoid errors during testing but there are already quite a bunch of errors when running yarn test
regarding non-implemented navigation features and I can only assume it's because we're clicking links and that tries to run code to navigate to it's href but I've not found a way to confirm this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not 100% sure since I didn't write it but I believe the idea is to not call setTimeout
in tests. Maybe @Maronato has more information for this
I updated the PR to send the event on ctrl/meta/shift and middle mouse click as well. I retested with Firefox on my Manjaro system and it seems to work fine. Tests are all green as well. Because of the istanbul ignore next above the if (not by me), it's not reflected in the coverage but basically all the issues this PR addresses are currently untested as far as automated tests are concerned. As you can see in the latest commit, I also organized the if conditions and added some comments to explain why we're checking for them. On top of that I removed a It would be nice to have more manual tests and some automated ones as well. What do you think feature wise? |
@Joelius300 Looks good to me, I'd like to get it integrated. Tests are the only thing missing now I think |
Can this PR get approved/merged? It's been 9 months. |
This avoids issues like Ctrl + Click overriding the current tab instead of opening a new one. Ctrl + Click now behaves like middle-mouse-click which is correct AFAIK.
bf948a6
to
f25543b
Compare
Rebased. Again, I do not feel comfortable writing tests for this by myself and would love to get some guidance to finalize this fix. |
@RobertJoonas Is working on outbound links in the main tracker. Could you also take a look at this one and make sure their behaviour is identical? No big rush but I thought it's quite relevant to what you're working on anyways. |
Sure, will do. |
Since the last update on this PR, the outbound link handling of the original script in the main repo has changed (namely plausible/analytics#2208). Would it be worth reworking the behavior in this script as well, to match the main script exactly? On top of this, I'm still doubtful that maintaining two different implementations of the exact same script is a good idea. The handlebars script of the main repo is supposed to be minimal and your main focus as it's the one people use when they add Plausible to their site using a script tag, I understand that. Unlike that script however, the library here allows you to integrate the code directly into an applications code which, apart from other benefits, improves reach as it's not blocked as often by tracker blockers. From my limited experience with building scripts like this, I would assume that it's possible to have a "heavy-weight" library (with TypeScript, multiple files/modules, etc.), that can yield all the same minimal scripts that you have in the main repo thanks to tree-shaking and bundlers. With one initial bulk of effort, this would help your users and you wouldn't have to worry about two scripts maintaining parity when adding new features or improving one. |
So when this can be merged? |
Description
As discussed in #12, currently the outbound link tracking implementation doesn't honor the
target
attribute of links. This PR aims to fix this by differentiating between_self
(default),_top
,_parent
and_blank
inspired by this workaround by @abett.I've successfully included this fix in my fork which I'm now using in my project (through a git submodule).
Unfortunately, there are no tests covering this change yet. I tried to get something working with the existing tests (I don't know jest) but failed. I think it's because navigation and the properties like
location.href
etc. aren't implemented/mocked in the testing environment and thus can't be used.So if anyone could assist me in this or point me in the right direction I'd be happy to add these before merging.
Related Issue
Fixes #12
Repro etc. can be found there.
Implementing #16 would make this change obsolete but this should work as a solid workaround until the time for #16 comes.
Types of changes
While it's technically a breaking change in that links with target attribute now behave differently than before the fix, they are now behaving as one would expect. AFAIK the behavior now matches the default browser behavior without interception albeit with a 150ms delay (for everything except
_blank
). This delay was also present before the fix and could be removed by #16 IIRC.In general no action should be necessary when this is implemented except maybe removing old workarounds. I'm assuming that nobody that knows of this bug is relying on it. That's why I checked both boxes.
Checklist: