Links Extension¶
The links
extension enables events that track link clicks on the site. This
extension provides ways to see what links it has detected, as well as support
for parsing links for their label and URL.
Installation¶
This extension can be enabled through Orbee's Platform. If you are manually controlling installation and setup, you can also fetch the plugin here:
<script async src="https://scripts.orb.ee/js-sdk/latest/links.js" />
This standalone installation sets up the extension's class on the window object,
under window.OaLinksExtension
. You can then extend your scope like this:
oa.getScope(YOUR_SCOPE).extend('links', OaLinksExtension);
Configuration¶
This extension requires no additional configuration at this time.
Methods¶
This extension has a variety of available attributes and functions to call.
links.links
¶
This is an object of links the extension is currently tracking; the key is the generated ID for that link instance, and the value is the link element on the web page.
links.links = {
"b92258ec-1b11-4b80-8111-729187e3c9f4": <a element-on-page>,
...
}
links.domWatcher
¶
This is an object that uses a
MutationObserver
to track changes to your website, and continuously add tracking to new links. It
is on by default; you can disable it with links.domWatcher.stop();
.
If stopped, you can also restart it with links.domWatcher.watch();
.
links.trackLink(linkEl)
¶
This function lets you manually enable tracking of a link on the web page. The DOM watcher automatically calls this method for all links it detects on your website.
links.parseLink(linkEl)
¶
This function lets you parse a link in the format our extension resolves things like the link's label as well as its destination URL. This function returns a proper link class that includes properties of the link.
Available methods/properties:
link.element
: returns the element of the link.link.name
: returns the name of the link.link.href
: returns the destination URL of the link.
Advanced¶
If you want to control when data is sent to Orbee, you can use the following methods to manually send link clicks to Orbee:
trackClick(linkEl)
¶
This function will track the click on a link. This does parse and send the name (label) and destination URL (href) of the link.
Events¶
The extension generates the following events:
Link Clicked¶
oa.track('link clicked', {
_id: "<link instance id>",
name: "linkName",
href: "https://destination-url.com/,
});
Listening¶
This extension does not listen for any events in the SDK.
Dependencies¶
This extension does not depend on any other extensions.