Get started with Transfon Gateway JavaScript API
Transfon Gateway provides a client-side JavaScript API to interact with the Transfon Gateway tag. The API allows you to queue events and perform checks asynchronously, even before the tag script has fully loaded.
Adds a custom event to the Transfon Gateway queue. This method can be called before or after the Transfon Gateway tag is loaded.
event (string)
Name of the event to track. Example: "page_view"
payload (object, optional)
Optional data associated with the event. Example: { userId: 12345 }
Usage Example:
// Queue a custom event
window._waf360.send("page_view", { userId: 12345 });
window._waf360.q until the tag is ready.Queues a Transfon Gateway check operation to fetch the current traffic and security evaluation. The callback is executed once the tag is ready and the response is retrieved.
callback (function, required)
A function that executes with the Transfon Gateway response data. The callback receives a single parameter: the response object.
window._waf360.check(function(data) {
console.log("Transfon Gateway check result:", data);
if (data.block) {
alert("Traffic is blocked");
}
});
{
"qs": false,
"ib": false,
"ic": true,
"dc": "AMAZON_AWS",
"ix": false,
"it": false,
"iv": false,
"geo": "GB",
"block": false
}
All API calls (send and check) are stored in the _waf360.q array until the Transfon Gateway tag is fully loaded. This allows you to invoke the API before the tag script is available:
window._waf360.send("signup", { plan: "premium" });
window._waf360.check(function(data) { console.log(data); });
When the tag initializes, it processes the queue in order, sending events and executing check callbacks.
In many cases, you may need to control which third-party vendor scripts are loaded based on the characteristics of your traffic. Using the Transfon Gateway JavaScript API, you can dynamically decide whether to load scripts depending on geographic location, quality check status, bot detection, or other security metrics. This approach helps:
The following examples demonstrate common scenarios for managing third-party vendor tags using window._waf360.check.
window._waf360.check(function(data) {
if (data.geo === "US") {
const script = document.createElement("script");
script.src = "https://example.com/us-only-script.js";
document.head.appendChild(script);
}
});
block statuswindow._waf360.check(function(data) {
if (!data.block) { // only load if traffic is not blocked
const script = document.createElement("script");
script.src = "https://example.com/allowed-script.js";
document.head.appendChild(script);
}
});
qs (quality check)window._waf360.check(function(data) {
if (data.qs) { // only load if traffic passed quality check
const script = document.createElement("script");
script.src = "https://example.com/quality-pass-script.js";
document.head.appendChild(script);
}
});
block and qswindow._waf360.check(function(data) {
// Load only if not blocked by rules and also passes quality check
if (!data.block && data.qs) {
const script = document.createElement("script");
script.src = "https://example.com/block-pass-script.js";
document.head.appendChild(script);
}
});