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

Add functionality to use navigator.sendBeacon #45

Closed
wants to merge 2 commits into from
Closed

Add functionality to use navigator.sendBeacon #45

wants to merge 2 commits into from

Conversation

A5rocks
Copy link

@A5rocks A5rocks commented Aug 26, 2022

Description

Use a better method of analytics posting.

Related Issue

Fixes #16.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

I think a followup to this would be using navigator.sendBeacon unless callback is passed. I would be OK with adding that into this.

@A5rocks
Copy link
Author

A5rocks commented Sep 21, 2022

@ukutaht Hello! Just making sure you've seen this PR. Do you have any opinions for whether navigator.sendBeacon should be the default (as mentioned in #16 or at the end of my PR explanation)?

Additionally you need to allow (approve?) the workflow to run :P

@ukutaht
Copy link
Contributor

ukutaht commented Sep 28, 2022

Hi!

We have considered it but have decided against using sendBeacon at this time. Sorry :/

@ukutaht ukutaht closed this Sep 28, 2022
@A5rocks
Copy link
Author

A5rocks commented Sep 28, 2022

Alright, thanks.

@A5rocks A5rocks deleted the sendBeacon branch September 28, 2022 11:55
@kotx
Copy link

kotx commented Sep 28, 2022

We have considered it but have decided against using sendBeacon at this time. Sorry :/

@ukutaht Are there any reasons for this? Just curious :)

@ukutaht
Copy link
Contributor

ukutaht commented Sep 29, 2022

The main reason is that we don't currently have team capacity to evaluate this change properly. We'd need to evaluate this approach before choosing to adopt it.

Adding sendBeacon with progressive enhancement will certainly do the following:

  1. Increases JS payload size
  2. Make the script more complicated
    2.1 Harder to use and understand
    2.2. More opportunities for errors
    2.3 Harder to maintain over time

In order to accept long-term maintenance of this complexity, strong arguments must be made. The main pieces of data I'm looking for are:

  1. How much bigger does the JS payload get
  2. What's the % increase/decrease in reliability when using sendBeacon?
    2.1 Need to test with different audiences as adblockers set navigator.sendBeacon = function() {}

These two numbers should give us good enough understanding to make a decision.

@lewisakura
Copy link

lewisakura commented Sep 29, 2022

As someone who also desires this feature it's a little disappointing to see this closed and I'm sure other people are too.

  1. Increases JS payload size
  2. Make the script more complicated
    2.1 Harder to use and understand
    2.2. More opportunities for errors
    2.3 Harder to maintain over time

Whilst I understand these points being a concern, the PR itself is about 5 extra lines of code, of which the majority is just adding the new useSendBeacon parameter. I wouldn't consider this extra complexity, personally, just extra flexibility to those who desire it, especially since the parameter is optional. Also, the error opportunities would most likely be the fault of the browser's implementation of sendBeacon, less so any change this PR creates. Maintenance-wise, with the way it's implemented, it shouldn't really need any.

  1. How much bigger does the JS payload get

Using yarn build:module, the built request.js file increases from 3,319 bytes to 3,710 bytes (~11.7%). Considering this also includes the new code comments, when minified I imagine this will barely be a dent in the overall bundle size. I'm aware Plausible is trying to be as lightweight as possible, but I believe that missing out on this feature for a (relatively) small increase in size is a bit extreme.

  1. What's the % increase/decrease in reliability when using sendBeacon?
    2.1 Need to test with different audiences as adblockers set navigator.sendBeacon = function() {}

The reliability would actually be increased. I don't have percents for you, but considering sendBeacon's purpose it would pretty much guarantee an event would be sent even after they navigate away from the page. It wouldn't be any less reliable than the current method. Regarding adblocking, I've experienced Plausible being adblocked on a few that I've tried so it's not much of a concern here if they no-op sendBeacon.

@earthboundkid
Copy link

FWIW, I'm evaluating Plausible for my company and using sendBeacon is one of our requirements. I'm just going to rewrite the JS myself to make it work. The flipside of Plausible's JS being 3KB is you can rewrite it yourself in an afternoon.

@A5rocks
Copy link
Author

A5rocks commented May 15, 2023

If you do end up rewriting it and decide it's good enough to share, mind doing so? We were going to use a rewritten version but decided that would be too much work! (I still have our untested version on disk... heh. It's for some time in the future, I suppose.)

@earthboundkid
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Using Navigator.sendBeacon for sending data
5 participants