5 minute read
Sending events using Beacon
The Beacon browser utility asynchronously sends a small amount of data over HTTP to the RudderStack server. To send the SDK events using this utility, set the useBeacon field in the load() call options to true.
The following table describes the above integer type parameters in detail:
The SDK flushes the queue when the default number of payloads is reached.
The SDK flushes the queue after the default time interval (in milliseconds) is reached.
There are two key advantages of using the Beacon utility to send your event payload:
The Beacon requests are optimized so that the browser waits until the CPU load is lower or until the network is free before making the actual requests, leading to better website performance.
The Beacon queue maintained by the browsers limits the total size of the elements present in the queue at any point and peaks at 64 KB.
Event delivery and retry mechanism
This section highlights some important points which will help you choose whether to use Beacon for sending your event payloads:
The requests sent from the SDK using the Beacon utility only push the events to the browser’s Beacon queue. Further, it depends on the browser’s engine to send these events from the queue. Hence, RudderStack does not guarantee if any events get discarded due to any 5xx or other network-related errors (request timed out, end resource unavailable, etc.).
The RudderStack queue handles approximately 500 hits per 30ms and ensures the eventual successful delivery of events after retries to Beacon.
Reduced core SDK size
This feature is deprecated and no longer supported by RudderStack.
requireIntegration call definition
The requireIntegration method contains the following two parameters:
The first parameter is a string or an array of strings containing the destination names.
You can also pass rudderanalytics.requireIntegration(“All”). This will fetch the plugins for all the native destinations connected to your source in the RudderStack dashboard.
The second parameter is a callback that accepts an object containing the names of the destinations successfully or unsuccessfully loaded on the page.
Currently, RudderStack supports the plugins only for Google Analytics, Hotjar, and HubSpot.
How it works
The SDK maintains a call queue, and the API calls are processed one after the other. The SDK blocks the processing of this call queue once you call the requireIntegration method.
Suppose the user makes a call rudderanalytics.requireIntegration("GA"). All the subsequent calls made to the SDK (such as page, track, alias, group, etc.) will get enqueued until the GAPlugin.js and Google Analytics’ analytics.js is loaded on the web page. Once the plugin and the end destination snippet is loaded, the calls in the queue will be processed, and the corresponding calls to analytics.js will start flowing.
For the above example, Google Analytics’ trackingId and other configuration settings are fetched from the RudderStack dashboard and the SDK is configured using these settings.
Sample call flow
The following workflow sums up the flow of the event payload when the user calls requireIntegration():
cookies, the cookies that are categorized as necessary are stored on your browser as they are as
for the working of basic functionalities of the website. We also use third-party cookies that
analyze and understand how you use this website. These cookies will be stored in your browser
consent. You also have the option to opt-out of these cookies. But opting out of some of these
have an effect on your browsing experience.
Necessary cookies are absolutely essential for the website to function properly. This
category only includes cookies that ensures basic functionalities and security
features of the website. These cookies do not store any personal information.
learn more about cookies and why we use them, visit our cookie
policy. We'll assume you're ok with this, but you can opt-out if you wish Cookie Settings.