AurumClick
ChaptersJavaScript plugins

DocumentationTeam and integrations

JavaScript plugins

On this page
  1. Where to create them
  2. Format
  3. Examples

Your own filters, redirects, actions and macros instead of Keitaro PHP scripts. A plugin is a single JavaScript file; it runs on edge in a sandbox: no network, files, database or timers, 5 ms per call. Built-in functions that create or walk strings and arrays (repeat, padStart, fill, map, join, Array.from, JSON.stringify, typed arrays…) accept no more than 1,000,000 elements: such a function runs to completion and is not interrupted by the time limit, and a huge size would stall clicks or exhaust edge memory. If a plugin fails or exceeds the limit, the click is not lost:

Type On error
filter does not match (the stream is skipped)
redirect a plain HTTP redirect to the destination URL
action “Do nothing” (an empty 200 response)
macro an empty string

Errors and limit overruns for each plugin are shown in “Maintenance → Status”; if they exceed 1 % of calls (with 100 calls or more), a warning appears there as well.

Where to create them

  • Settings → Plugins → New plugin: a template by type, a code editor, Run on a test click (Germany, Android, Chrome, sub_id_1 = fb_123; the fields can be changed).
  • Server folder /opt/aurumclick/data/plugins/{filters,redirects,actions,macros}/*.js: imported at startup and with the Rescan folder button. Such a plugin is edited in the file; in the admin panel it can only be turned on or off.

Plugins are stored in the database and reach every edge together with the configuration, so there is no need to copy files to cluster servers. Plugins are managed by administrators; changes are recorded in the audit log.

Format

export default {
  key: "geo_prefix",            // Latin letters, digits, _; must not match a built-in one
  name: "Country + prefix",     // name in the interface
  schema: { … },                // JSON Schema of the settings (filter, action) — the form in the stream
  match(click, payload) { … },  // filter → true/false
  render(ctx) { … },            // redirect, action → { status, headers, body }
  process(click, conversion, ...args) { … }, // macro → string
};

click holds the click fields (same as macros): country, region, city, isp, operator, connection_type, device_type, device_brand, device_model, os, os_version, browser, browser_version, user_agent, language, referrer, ip, domain, path, keyword, source, sub_id_1…sub_id_30, extra_param_1…extra_param_10, bot, proxy, is_unique_campaign, campaign_id, datetime (UTC). Filters also get params, the GET parameters of the link; after the stream is chosen (redirects, actions, macros) there are subid, stream_id, landing_id, offer_id.

Examples

A filter: a country from a list and sub_id_1 with a prefix:

export default {
  key: "geo_prefix",
  name: "Country + sub_id_1 prefix",
  schema: {
    type: "object",
    properties: {
      countries: { type: "array", title: "Countries", items: { type: "string" } },
      prefix: { type: "string", title: "Prefix" },
    },
    required: ["countries", "prefix"],
  },
  match(click, p) {
    return p.countries.includes(click.country) && click.sub_id_1.startsWith(p.prefix);
  },
};

In a stream the filter appears in the “Plugins” group, and the settings form is built from schema; settings that do not fit the schema are not saved.

A redirect through a page with a delay (ctx.url is the destination URL, ctx.integration is direct, script or iframe):

export default {
  key: "delayed",
  name: "After 2 seconds",
  render(ctx) {
    return {
      status: 200,
      headers: { "Content-Type": "text/html; charset=utf-8" },
      body: '<meta http-equiv="refresh" content="2;url=' + ctx.url + '">',
    };
  },
};

An action: ctx.payload is the text from the stream with macros already substituted (if the action has a schema, it is JSON — JSON.parse(ctx.payload)).

A macro: {geo_slug} or {geo_slug:-} in offer, landing and stream links and in postbacks; in an S2S postback the second argument is the conversion (tid, status, original_status, revenue, cost, datetime), otherwise null:

export default {
  key: "geo_slug",
  name: "Geo slug",
  process(click, conversion, sep = "_") {
    return [click.country, click.city].filter(Boolean).join(sep).toLowerCase();
  },
};

Built-in filters, redirects, actions and macros take priority: a plugin key cannot match them.

Didn’t find an answer?

Support