Javascript file
1. Overview
An AB Tasty widget requires a unique JavaScript file that will be injected into the client’s website. The JavaScript file's location must be specified explicitly in the package.json
, in the main
field, as shown below:
"main": "main.js"
You can easily code directly into a single file. To get the latest JavaScript features, we recommend using a bundler like rollup.js or webpack in combination with a transpiler like bublé or babel. Please note that the widget generated by the AB Tasty Widget CLI uses rollup.js and babel out of the box. In this case, the bundled file will probably be generated in a folder such as /dist
or /build
.
You will then need to modify the location of your main file in your package.json
as follows:
"main": "dist/main.js"
Note: The widget generated by the AB Tasty Widget CLI uses rollup.js and babel out of the box.
2. Resources
Globals variables
The following variables are global and can be used anywhere in your javascript file:
PACKAGE
: the name of your package.
DATA
: all the options from the configuration form of the widget.
TEST_ID
: the id of the test the widget is currently running (works only in production, in developpment the value is always 1).
Tracking events
You can track events with the ABTastyEvent
function
ABTastyEvent('Name of your event', null, TEST_ID)
Widget Utils
Widgets Utils is a library containing a package of useful functions, applicable to the Widgets.
You can find it here:
https://www.npmjs.com/package/@abtasty/widget-utils