Avortyx View full page

Tracking & Attribution

Expressions & Functions

Clean, format and calculate call and lead data on the fly, inside routing filters, webhooks and postbacks.

Expressions let Avortyx reshape and calculate data as calls and leads move through it: clean a name before it reaches a buyer, compute a payout, format a date for a postback. Functions can be nested inside each other, so small pieces combine into real logic.

They work anywhere Avortyx fills in tokens, including:

  • Default values for contact fields
  • Webhook URLs and postback bodies
  • Filters in your routing rules

Every expression has a type (String, Integer, Float or Time), and its arguments are converted to that type before it is evaluated.

Sample data

The examples on this page use the data below; the result of each expression follows its =>

{
  "first_name": "John",
  "last_name": "Smith",
  "birth_year": "1977",
  "yob": 2012,
  "mortgage_amount": 65000,
  "debt_amount": 8283.25,
  "started_at_utc": "2020-06-21 22:35:12 UTC"
}

A String expression

Arguments are treated as text before the expression runs.

[!String! ALPHANUMERIC_DASH(CONCAT([first_name], " ", [last_name])) !!]
=> john-smith

A Time expression

Arguments are treated as times before the expression runs.

[!Time! DATE_FORMAT(DATE_ADD([started_at_utc], 86400), "%Y-%m-%d %M-%S") !!]
=> "2020-06-22T18:35:12"

Functions

case(statement)

logic

Tests several conditions in order and returns the output of the first one that is true.

ArgumentRequiredInfo
statementRequiredThe statement that will be evaluated.
CASE('apple' WHEN 'apple' THEN 1 WHEN 'banana' THEN 2 ELSE 3 END)
=> 1

if(statement, output_when_true, output_when_false)

logic

Checks a condition and returns one value when it holds and another when it does not.

ArgumentRequiredInfo
statementRequiredThe statement that will be evaluated.
output_when_trueRequiredThe value that will be outputted if the statement evaluates to true.
output_when_falseRequiredThe value that will be outputted if the statement evaluates to false.
IF(15 < 10, 10, 20)
=> 20

avg(*values)

numeric

The mean of the numbers you pass in.

ArgumentRequiredInfo
*valuesRequiredThis function accepts an unlimited number of numeric values.
AVG(1,2,3,4)
=> 2.5

count(*values)

numeric

How many values were passed in.

ArgumentRequiredInfo
*valuesRequiredThis function accepts an unlimited number of numeric values.
COUNT(1,2,3,4)
=> 4

max(*values)

numeric

The largest of the numbers you pass in.

ArgumentRequiredInfo
*valuesRequiredThis function accepts an unlimited number of numeric values.
MAX(1,2,3,4)
=> 4

min(*values)

numeric

The smallest of the numbers you pass in.

ArgumentRequiredInfo
*valuesRequiredThis function accepts an unlimited number of numeric values.
MIN(1,2,3,4)
=> 1

round(value, precision)

numeric

Rounds a number to the closest value at the precision you give.

ArgumentRequiredInfo
valueRequiredThe value to be rounded. EG:
ROUND(8.8) => 9
ROUND(8.2) => 8
precisionOptionalThe precision to be used. EG:
ROUND(8.75, 1) => 8.8
ROUND(8.2)
=> 8

rounddown(value, precision)

numeric

Rounds a number down, toward the lower value, at the precision you give.

ArgumentRequiredInfo
valueRequiredThe value to be rounded. EG:
ROUND(8.8) => 8
precisionOptionalThe precision to be used. EG:
ROUND(1.234, 2) => 1.23
ROUNDDOWN(1.234)
=> 1

roundup(value, precision)

numeric

Rounds a number up, toward the higher value, at the precision you give.

ArgumentRequiredInfo
valueRequiredThe value to be rounded. EG:
ROUND(8.8) => 9
precisionOptionalThe precision to be used. EG:
ROUND(1.234, 2) => 1.24
ROUNDUP(1.234)
=> 2

sum(*values)

numeric

Adds the numbers you pass in.

ArgumentRequiredInfo
*valuesRequiredThis function accepts an unlimited number of numeric values.
SUM(1,2,3,4)
=> 10

alphanumeric_dash(value)

string

Keeps only letters (a-z, A-Z) and digits (0-9), turns spaces into dashes and trims spaces from both ends. Handy for slugs and IDs.

ArgumentRequiredInfo
valueRequired
ALPHANUMERIC_DASH(" ./;!!!]  hello waffle world!@#$%^&*($)  ")
=> "hello-waffle-world"

alphanumeric_underscore(value)

string

Keeps only letters (a-z, A-Z) and digits (0-9), turns spaces into underscores and trims spaces from both ends.

ArgumentRequiredInfo
valueRequired
ALPHANUMERIC_UNDERSCORE(" ./;!!!]  hello waffle world!@#$%^&*($)  ")
=> "hello_waffle_world"

base64_decode(value)

string

Decodes a Base64 string (RFC 2045), skipping any characters outside the Base64 alphabet.

ArgumentRequiredInfo
valueRequired
BASE64_DECODE('dGVzdA==')
=> 'text'

base64_encode(value)

string

Encodes a value as Base64 (RFC 2045), with a line break after every 60 encoded characters.

ArgumentRequiredInfo
valueRequired
BASE64_ENCODE('text')
=> 'dGVzdA=='

concat(*values)

string
ArgumentRequiredInfo
*valuesRequiredThis function accepts an unlimited number of string values.
CONCAT('AB', 'CD', 'EF')
=> "ABCDEF"

contains(search, value)

string
ArgumentRequiredInfo
searchRequiredOutputs true if [value] contains this string.
valueRequiredThe string that will be checked.
CONTAINS('ABCD', 'A')
=> true

date_add(value, seconds)

string

Moves a date forward by a number of seconds.

ArgumentRequiredInfo
valueRequiredThe date that will be modified.
secondsRequiredThe seconds that will be added.
DATE_ADD([started_at_utc], 86400)
=> "2020-06-29 11:34:25 -0400"

date_format(value, format)

string

Writes a date in the format you choose.

ArgumentRequiredInfo
valueRequiredThe date that will be modified. EG '2020-06-29 11:22:57 -0400'
formatRequiredSpecifies the format for the date. The following characters can be used.

Date (Year, Month, Day):
%Y - Year with century
%y - year % 100 (00..99)
%m - Month of the year, zero-padded (01..12)
%B - The full month name (``January'')
%b - The abbreviated month name (``Jan'')
%d - Day of the month, zero-padded (01..31)
%j - Day of the year (001..366)

Time
%H - Hour of the day, 24-hour clock, zero-padded (00..23)
%I - Hour of the day, 12-hour clock, zero-padded (01..12)
%P - Meridian indicator, lowercase (``am'' or ``pm'')
%p - Meridian indicator, uppercase (``AM'' or ``PM'')
%M - Minute of the hour (00..59)
%S - Second of the minute (00..59)
%L - Millisecond of the second (000..999)
%N - Fractional seconds digits, default is 9 digits (nanosecond)
%z - Time zone as hour and minute offset from UTC (e.g. +0900)

Weekday
%A - The full weekday name (``Sunday'')
%a - The abbreviated name (``Sun'')
%u - Day of the week (Monday is 1, 1..7)
%w - Day of the week (Sunday is 0, 0..6)

Seconds since the Unix Epoch
%s - Number of seconds since 1970-01-01 00:00:00 UTC.
%Q - Number of milliseconds since 1970-01-01 00:00:00 UTC.
DATE_FORMAT([started_at_utc], "%Y-%m-%d %M-%S")
=> "2020-06-22T18:35:12"

date_parse(value, format)

string

Reads a date or time written in plain language and turns it into a date.

ArgumentRequiredInfo
valueRequiredThe date or natural language expression.

Simple Examples
thursday
november
summer
friday 13:00
mon 2:35
4pm
yesterday
today
tomorrow
last week
next week

Complex Examples
3 years ago
a year ago
5 months from now
7 hours ago
7 days from now
in 3 hours

Specific Dates & Times
22nd of june at 8am
1979-05-27 05:00:00
03/01/2012 07:25:09.234567
2013-08-01T19:30:00.345-07:00
2013-08-01T19:30:00.34-07:00
formatOptional
DATE_PARSE("30 days from now")
=> "2020-07-29 15:42:57 UTC"

date_subtract(time, time_or_decimal)

string

Takes a timestamp or a number of seconds away from a date.

ArgumentRequiredInfo
timeRequiredThe timestamp to be manipulated.
time_or_decimalRequiredThe timestamp or decimal that will be subtracted from the first argument time.
DATE_SUBTRACT([current_time_utc], [started_at_utc])
=> "2020-06-29 11:34:25 -0400"

date_to_time_zone(value, time_zone)

string

Converts a date into another time zone.

ArgumentRequiredInfo
valueRequired[lead_created_at]
time_zoneRequired
Examples Time Zones:
DATE_TO_TIME_ZONE([lead_created_at], "Eastern Time (US & Canada)")
=> "2020-07-29 15:42:57"

digest_md5(value)

string

Returns the MD5 hash of a value (RFC 1321): a 128-bit (16-byte) digest.

ArgumentRequiredInfo
valueRequired
DIGEST_MD5('text')
=> 90015098...

digest_sha1(value)

string

Returns the SHA-1 hash of a value, as defined by NIST in FIPS PUB 180-1.

ArgumentRequiredInfo
valueRequired
DIGEST_SHA1('text')
=> a9993e36...

digest_sha2(value)

string

Returns the SHA-256 hash of a value: a 256-bit digest computed over 512-bit blocks.

ArgumentRequiredInfo
valueRequired
DIGEST_SHA2('text')
=> ba7816bf8...

downcase(value)

string

Makes every letter lowercase.

ArgumentRequiredInfo
valueRequired
DOWNCASE("HELLO World")
=> "hello world"

find(search, value)

string
ArgumentRequiredInfo
searchRequiredFinds the integer index of [search] in [value]. If [search] is missing in [value] it outputs nothing.
valueRequiredThe string that will be manipulated.
FIND('BC', 'ABCD')
=> 2

generate_uuid()

string

Creates a new universally unique identifier (UUID).

GENERATE_UUID()
=> "518e8221-a29e-72c1-a716-486156481234"

left(value, length)

string
ArgumentRequiredInfo
valueRequiredThe string that will be manipulated.
lengthRequiredThe number of characters to extract starting from the left.
LEFT('ABCD', 2)
=> "AB"

len(value, length)

string
ArgumentRequiredInfo
valueRequiredThe string that will be manipulated.
lengthRequiredOutputs the length of the string as an integer.
LEN('ABCD')
=> 4

oauth_access_token(oauth_connection_key)

string

Fetches an access token from one of your OAuth connections, for authenticated webhooks.

ArgumentRequiredInfo
oauth_connection_keyRequiredThe key that you chose when creating the connection.
OAUTH_ACCESS_TOKEN('marchex_v2')
=> "sdjf9032fj239fj90sjf90wjf390"

right(value, length)

string
ArgumentRequiredInfo
valueRequiredThe string that will be manipulated.
lengthRequiredThe number of characters to extract starting from the right.
RIGHT('ABCD', 2)
=> "CD"

seconds_to_hms(seconds)

string

Shows a number of seconds as HH:MM:SS, for example a call duration.

ArgumentRequiredInfo
secondsRequired
SECONDS_TO_HMS(3672)
=> "01:01:12"

split(value, pattern, index)

string

Breaks a value apart at a delimiter and returns the piece at the index you ask for.

ArgumentRequiredInfo
valueRequiredThe text that will be modified.
patternRequiredThe pattern is a String. Its contents are used as the delimiter when splitting str. If pattern is a single space, str is split on whitespace, with leading and trailing whitespace and runs of contiguous whitespace characters ignored.
indexRequiredIndex is the index of the split substrings that will be returned. Examples:

SPLIT([full_name], ' ', 2) would return "Smith"
SPLIT("John Andrew Smith", ' ', 0) would return "John"
SPLIT("John Andrew Smith", ' ', 1) would return "Andrew"
SPLIT("2019-01-12", '-', 1) would return "01"
SPLIT("John Smith", " ", 1)
=> "Smith"

strip(value)

string

Trims whitespace from the start and end of a value.

Whitespace here means null, horizontal tab, line feed, vertical tab, form feed, carriage return and space.

ArgumentRequiredInfo
valueRequired
STRIP("    hello world   ")
=> "hello world"

substitute(value, search, replacement)

string
ArgumentRequiredInfo
valueRequiredThe string that will be manipulated.
searchRequiredThe text that will be replaced.
replacementRequiredThe replacement text.
SUBSTITUTE('green cat, blue cat, yellow cat', 'cat', 'dog')
=> "green dog, blue cat, yellow cat"

substitute_all(value, search, replacement)

string

Replaces every occurrence of one piece of text with another.

ArgumentRequiredInfo
valueRequiredThe string that will be manipulated.
searchRequiredThe text that will be replaced.
replacementRequiredThe replacement text.
SUBSTITUTE_ALL("green cat, blue cat, yellow cat", "cat", "dog")
=> "green dog, blue dog, yellow dog"

substring(value, start, length)

string

Returns a slice of a string: the characters in the range you specify.

ArgumentRequiredInfo
valueRequiredThe text that will be modified
startRequiredThe position where to start the extraction. First character is at index 0.
lengthRequiredThe number of characters to extract. Pass -1 to extract the rest of the string.
SUBSTRING([started_at_offer_time_zone], 0, 9)
=> "2020-09-20"

titleize(value)

string

Capitalizes the first letter of every word.

ArgumentRequiredInfo
valueRequired
TITLEIZE("  hello world  ")
=> "  Hello World  "

to_currency(value, symbol)

string

Formats a number as money, with a currency symbol and thousands separators.

ArgumentRequiredInfo
valueRequiredThe numeric amount to be formatted as currency.
symbolOptionalOptional symbol to represent the currency (e.g., $, €, £). Defaults to $.
TO_CURRENCY("1234567.89")
=> "$1,234,567.89"
TO_CURRENCY("1234567.89", "€")
=> "€1,234,567.89"

to_formatted_number(args, **, block)

string

Formats a phone number the way it is written locally.

ArgumentRequiredInfo
argsOptional
**Optional
blockOptional
TO_FORMATTED_NUMBER(" + 1 719-852-2985 ")
=> "(719) 522-0377"

to_integer(value)

string

Turns a value into a whole number.

ArgumentRequiredInfo
valueRequired
TO_INTEGER(' 15.15 ')
=> 15

to_json(value)

string

Turns a value into a JSON string.

ArgumentRequiredInfo
valueRequired
TO_JSON({example: "value"})
=> {"example": "value"}

to_phone_number(value)

string

Normalizes a phone number into international format.

ArgumentRequiredInfo
valueRequired
TO_PHONE_NUMBER(" 1 (719) 852 2985 ")
=> "+17198522985"

upcase(value)

string

Makes every letter uppercase.

ArgumentRequiredInfo
valueRequired
UPCASE("Hello World")
=> "HELLO WORLD"

url_decode(value)

string

Turns percent-encoded sequences (a % followed by two hex digits) back into the characters they stand for.

ArgumentRequiredInfo
valueRequired
URL_DECODE("hello%20world%2C%20how%20are%20you%3F")
=> "hello world, how are you?"

url_encode(value)

string

Percent-encodes every character that is not a letter or digit, so the value is safe in a URL.

ArgumentRequiredInfo
valueRequired
URL_ENCODE("hello world, how are you?")
=> "hello%20world%2C%20how%20are%20you%3F"

usa_zip_code(value)

string

Keeps only the first five digits, turning a ZIP+4 into a standard U.S. ZIP code.

ArgumentRequiredInfo
valueRequired
USA_ZIP_CODE("USA 90210 OR")
=> "90210"

Ready to route your first call?

Point a number at Avortyx and calls start scoring, routing and settling on the first ring. Request access, or walk through your traffic with our team.