Beacon Plugin
The beacon plugin enables users to send and/or collect beaconing information from assets in a normalized API. It exposes a common API for publishing beacons from an asset library, and will automatically attach itself to the current view, enabling additional meta-data to be added to each event.
Consuming Beacons
Beacon Format
By default, the beacon plugin returns beacons in the following format:
Usage
Add the beacon plugin to a player:
Beacons can be published directly by the plugin, but in most cases, a platform specific adapter is recommended.
Just like with the core variant, to add support for beaconing in the react
player, add the plugin to Player:
This will add additional React Context to the running player for the producers from asset-libraries to leverage.
Beaconing on the JVM platform (including Android) is done with an instance of the BeaconPlugin
. By default, the Android Player includes a wrapper of the core beacon plugin. The Android Player can be configured to override the default BeaconPlugin by passing a different BeaconPlugin implementation on instantiation which can contain further configuration.
Without additional configuration, the BeaconPlugin doesn’t provide much value. Beacons must be explicitly handled in order to forward them to an analytics platform (segment, Trinity, etc.). This is done by calling registerHandler(handler: (String) -> Unit)
with a callback.
There may be some beacons that are fired automatically by the BeaconPlugin implementation, but in most cases, there are additional beacons that should be fired on some interaction (i.e. user tapping button asset). This is done by calling beacon(action: String, element: String, asset: Asset, data: Any? = null)
with the relevant information.
For convenience, there are several extension methods for utilizing a pre-installed BeaconPlugin from Player. If there isn’t a BeaconPlugin installed, Player will produce a warning log.
The base RenderableAsset
class provides an additional helper to make beaconing less verbose from an asset perspective.
CocoaPods
Add the subspec to your Podfile
Swift Usage
To receive Beacon events from Player in iOS, add the BeaconPlugin
to your plugin array:
If you are modifying the beacon using core BeaconPlugin
plugins:
Beacon Plugins
Similar to how Player accepts plugins, the beacon-plugin itself accepts a list of plugins. These are able to mutate and augment the beacon payload as it makes its way through the publishing pipeline.
There are 3 hooks that are currently exposed:
buildBeacon
- Assembles a given beacon ffor publishingcancelBeacon
- Given a current beacon, determine if it should be published or not.publishBeacon
- Receive the final becaon. This is a substitute for thecallback
in the beacon plugin options.
Publishing Beacons
beacon expression
The beacon plugin adds support for a beacon
expression that can be referenced within content. Each beacon referenced from this expression will be assumed to originate from a view
(no local asset information will be attached)
Assets
useBeacon hook
The @player-ui/beacon-plugin-react
package exports a hook that assets can leverage to publish beacons.
The useBeacon
hook takes base options that apply broadly, and returns a function with those options as the base. You can then pass event specific information when calling beacon
.
Example
Using the base RenderableAsset
’s helper function in this example fires off a basic beacon with no adjustment to format as well as empty data upon button click
Example
The SwiftUIBeaconPlugin attaches a BeaconContext to the root of the SwiftUI view tree as an environment value, so when included any asset can use that context to send a beacon, if the context is in the environment: