Tag API
Reference documentation for data provided by AB Tasty's JavaScript Tag.
What's the AB Tasty's API?
AB Tasty's Tag provided an API to help you getting data used internal to make your campaigns, settings and other features working. This API is versioned and could have at its maximum 3 different versions at the same time:
the current version to use (this is the one you should use during your developments)
a deprecated version (an old version which is going to be removed in the following months)
a future version (could be under development and should be used in specific cases due to potential change)
How to use it?
All versions of the AB Tasty's API are available in the main window object provided by the Tag with:
window.ABTasty.api
Version 1 (v1
)
v1
)getValue
The getValue()
method of the API v1 return the value associated to the keys you provided as parameter. If no value is found, the returned method throw an error.
Syntax
window.ABTasty.api.v1.getValue(key0 [, key1, ..., keyN, callback]);
Parameters
keyN
: The keys which constitute the path of the value you want to get.callback
: A function which is going to be called once the value is updated. (the callback is only applied to mutable values) The callback take as input one parameter:the new value after its updated
an array of the requested keys
Return value
The value associated to the keys you provided as parameters.
Examples
Calling with a single key:
// Let's say the current visitor have the Id: 8t77xk264w3gtr6h
const abtastyVisitorId = window.ABTasty.api.v1.getValue('visitorId');
console.log(abtastyVisitorId); // 8t77xk264w3gtr6h
Calling with a multiple keys:
// Let's say AB Tasty's Tag have been started and run campaigns
const isAbTastyStarted =
window.ABTasty.api.v1.getValue('general', 'started');
console.log(isAbTastyStarted); // true
Calling with a callback:
// Let's say the visitor didn't give the consent to AB Tasty after few minutes
const myCallback = (newValue, keys) => {
console.log(newValue);
console.log(keys);
};
const abTastyHasConsent =
window.ABTasty.api.v1.getValue('general', 'consent', myCallback);
console.log(abTastyHasConsent); // false
// 1 minutes later, visitor give consent to AB Tasty's Tag
// myCallback() is called and following logs are displayed:
// true (corresponding to newValue)
// ['general', 'consent'] (corresponding to keys)
Usable keys
The keys are nested so you should use them in the order described in the list.
Mutable keys means that you can listened any changes of the value by passing a callback
method as last parameters.
account: returns a record containing all the configuration of the account
taginfos: returns a record containing all infos about the tag: semantic version, branch version, etc
events: (mutable) returns a record of all custom events dispatched by the Tag
{event's name}: (mutable) returns a record containing
status
anddetail
of the event. (Please refer to EventState documentation)
general: (mutable) returns a record containing information on status of the Tag
consent: (mutable) returns a boolean indicated if consent to AB Tasty has been granted
started: (mutable) returns a boolean indicated if Tag have been started
lastUpdateDate: returns a string indicated the last update date and time of the tag. Format:
yyyy/MM/dd hh:mm:ss z
visitorId: returns a string with the actual visitor Id
Last updated
Was this helpful?