Investigate beacon API for snowplow JS API
From @ali-gitlab
From Beacon's docs:
The Beacon interface is used to schedule an asynchronous and non-blocking request to a web server. Beacon requests use the HTTP POST method and requests typically do not require a response.
From Snowplow Docs:
The Beacon interface is used to schedule asynchronous and non-blocking requests to a web server. This will allow events to be sent even after a webpage is closed.
This seems to satisfy @timzallmann's request to make this non-blocking and also reduce pageUnloadTimer
to 0 ms.
With Beacon, it seems that @a_akgun your suggestion of We may move active pages ( for example, contact sales experiment etc cc @dreedy / @s_awezec ), to open links in a new tab to guarantee timely registration of events.
may be an unnecessary step since with Beacon events can be sent even after a webpage is closed
.
Is there a simple way we can test this solution before a rollout on production? In my opinion, testing this across browsers will be very difficult to do. We may need to do the rollout and simply monitor link_click
tracking event volume for a few days (as a benchmark, every day we receive 1.3M link_click events).
Can we use beacon
here?
https://github.com/snowplow/snowplow-javascript-tracker/issues/719#issuecomment-582973637 mentions that you could drop pageUnloadTimer
to 0 with beacon
.
Snowplow docs about beacon
: https://docs.snowplowanalytics.com/docs/collecting-data/collecting-from-own-applications/javascript-tracker/general-parameters/initializing-a-tracker-2/#Beacon_API_support
I've never heard of the Beacon API before, so I took a quick glance at MDN: https://developer.mozilla.org/en-US/docs/Web/API/Beacon_API
Requests are guaranteed to be initiated before a page is unloaded and they are run to completion, without requiring a blocking request
Example use cases of the Beacon API are logging activity and sending analytics data to the server.
Seems like it fits our use case.
Supported by 95.25%
of users according to https://caniuse.com/?search=sendbeacon
It's not supported by IE, but we dropped support for that a few months ago, according to https://docs.gitlab.com/ee/install/requirements.html#supported-web-browsers.
Steps
-
Check Browser support for gitlab user base -
Web server and configuration support -
Proof of concept how it works on gitlab.com scale -
Investigate Beacon API stability for snowplow implementation