Skip to main content
Version: v72

Variables and Functions in Altcraft

Profile Data

Profile Data
DescriptionVariable
Email address{lead.email}
Phone list{lead.phones}
First name{lead._fname}
Last name{lead._lname}
Birth date{lead._bdate}
Gender{lead._sex}
Registration date{lead._regdate}
Registration IP{lead._regip}
Registration city{lead._regcity}
Registration country{lead._regcountry}
Registration URL{lead._regurl}
IP address{lead._ip}
City{lead._city}
Country{lead._country}
Region{lead._region}
Postal code{lead._postal_code}
Time zone{lead._tz}
Vendor{lead._vendor}
Profile ID{lead._id}
XXM hash{lead._xxm}
XX hash{lead._xxh}
MD5 hash{lead._md5}
Custom field{lead.field_name}

Subscriptions

Profile Subscriptions
DescriptionVariable
Subscription email address{subscription.email}
Email domain{subscription.email_domain}
Subscription email list{subscription.emails}
Subscription phone{subscription.phone}
Subscription phone list{subscription.phones}
Push subscriptions list{subscription.pushes}
MD5 of email{subscription.email_md5}
MD5 of phone{subscription.phone_md5}
Subscription hash{subscription.hash_id}
Primary subscription field{subscription_field("channel" "field_name" resource_id)}

channel — string like "email"

field_name — name of field like "domain"

resource — ID like 10

The subscription_field function allows inserting fields from subscriptions regardless of the current message channel. For example:

{subscription_field("sms" "phone")}

If multiple subscriptions match, the one with the highest priority is selected.

Available fields:

ChannelFieldDescription
emailemailEmail address
domainEmail domain
domain_groupDomain group
md5MD5 hash
smsphonePhone
md5MD5 hash
pushsubscription_idPush subscription ID
bundle_idiOS APNs app bundle ID
providerPush provider
tip

Similarly, data from custom channel subscriptions can be inserted. Fields in main channels match the SID fields you define when creating the channel.

UTM

UTM Variables

If a profile has UTM tags in their card, they can be inserted into message templates.

DescriptionVariable
UTM campaign{lead._utm_campaign}
UTM source{lead._utm_source}
UTM medium{lead._utm_medium}
UTM content{lead._utm_content}
UTM term{lead._utm_term}

External JSON

External JSON Content

External JSON is a way to generate dynamic messages with content from your server at the moment of sending.

Details: Using JSON Content in Messages

Use {json.variable} in text. list and object types support loops. Use {json.object.key_name} for keys.

Market

Using Market Variables

To include order and product info in messages, insert market variables into the template. More: Using Market Variables in Messages

Date and Time

Date and Time Variables
DescriptionVariableExample
Formatted date{format}{format datenow "%Y-%m-%D %H:%M:%S timezone, %I am"}2018-12-25 18:56:10 +03:00, 6 pm
Raw date{datenow}2018-12-25T18:56:10+0300
Add date{adddate()}{adddate(datenow 0 0 3)}2018-12-27T18:56:10+0300
Full year{yearlong}2018
Short year{year}18
Month{month}12
Day{day}10
24-hour{hours}18
12-hour{hours12}06
AM/PM{ampm}PM
Minutes{minutes}56
Seconds{seconds}10

Output Functions

Output Functions
DescriptionVariableExample
Number formattingformat{format 1000000000 ","}1,000,000,000
Variable lengthlength{length("abc")}3
Array of valuesarray{array[1 "2" 3.3]}[1 2 3.3]
Random array elementrandomize{randomize(array[1 2 3])}1

Example: {randomize(lead.Favourite_genres)}"Detective"
Array limitlimit{limit(array[1 2 3] 2)}[1 2]
Check if number is eveniseven{iseven(2)}true
{iseven(3)}false
URL encodingurlencode{urlencode(lead._regurl)}http%3A%2F%2Ftest.testdomain.com%2Fsomething
URL decodingurldecode{urldecode(lead._regurl)}http://test.testdomain.com/something
Uppercase all lettersuppercase{uppercase("text")}TEXT
Uppercase first letteruppercasefirst{uppercasefirst("john")}John

Encryption

Encryption and Hashing

Template variable encryption is used when data must be passed via a URL without being exposed in server logs or to the user. For example, you may want to encode pre-filled form data using base58 for decoding on the website side.

Use the crypt function in the template editor via the </> button → Encryption:

{crypt(algorithm field key)}

Supported algorithms:

  • base58
  • base64
  • sha1
  • sha256
  • aes
  • blowfish

For sha1, sha256, aes, and blowfish you must provide a key.

AES and Blowfish details:

AESBlowfish
Initialization vectorFirst 16 bytesFirst 8 bytes
ModeCFBCBC
Key length128-bit (16 chars)64-bit (8 chars)
Paddingzero paddingzero padding
tip

All encryption/decryption uses Base64URL encoding.

Examples:

{crypt(base58 lead._fname)}
{crypt(base64 lead._lname)}
{crypt(sha256 lead.custom_field "encrypt_key")}
{crypt(sha1 lead._city "encrypt_key")}
{crypt(aes lead._fname "key1234567891234")}
{crypt(blowfish lead._fname "key12345")}

For string values, wrap in quotes. Numbers can be passed as-is:

{crypt(base58 "value")}
{crypt(base64 42)}

Hash algorithms also support optional salt:

  • md5 + salt
  • xxh32 + salt
  • xxh64 + salt

Same syntax:

{crypt(md5 subscription.email "salt")}
{crypt(xxh32 loyalty.new2.promocode "salt")}
{crypt(xxh64 json.text "salt")}

Encrypted values are Base64-encoded.

Logical Expressions

Logical Expressions

Logical expressions are explained in detail here.

For simple conditions, use the following structure:

{if lead.age gte 18}
18 or older.
{else}
Under 18.
{end}

Fragments

Message Fragments

Fragments are reusable blocks used across multiple messages—such as headers, footers, or social media blocks.

To insert a fragment:

{fragment.<fragment_shortname>}

To insert a random fragment:

{randomfragment[fragment.name1 fragment.name2 fragment.name3]}

More on fragment usage: this article.

Parameters

Parameters
DescriptionVariable
Sent message ID (SMID){send_message_id}
Resource token{resource_token}
Template ID{msgid}
Campaign ID{campid}
Resource ID{resid}
Database ID (profile list){listid}
Campaign SUBID{subid}
Resource name{resname}
Database name{listname}
Message type{msg_type}
Resource URL{resurl}
Resource domain{resdomain}
Message name{msgname}
Campaign name{campname}
SMS sender name{from_name_sms}
Attribute value {attribute_value("attribute")}, where "attribute" is the API name of the attribute

Service

Service Parameters
DescriptionVariable
API Content{apicontent.field_name}
Cancel message delivery{cancel}

Tracking

Tracking Variables
DescriptionVariable
Tracking domain{trkdomain}
Open tracking pixel{pixel}
Read tracking pixel{read}
Preferences link{preferences}
Unsubscribe link{unsubscribe}
Global unsubscribe link{globalunsubscribe}
Add to suppression list{suppress}
Web version link{webversion}

Scenarios

Scenario Variables
DescriptionVariable
Scenario name{workflow_name}
Scenario ID{workflow_id}
Scenario node ID{node_id}
Scenario node type{node_type}

Emoji

You can insert emoji into your message templates. To do so, select the emoji from the variables menu in the template editor.

Profile Relations

Profile Relations

General syntax:

{relation.[relation_shortname].[direct|reverse].[property].[count|total|top]}

Example: count of direct relations by profit property:

{relation.managers_loyal.direct.profit.count}

Top reverse relations by profit, using loop to output:

{for $index $item = relation.managers_loyal.reverse.profit.top}
{$item.lead._fname} {$item.lead._lname} ({$item.value} profit)
{else} There is no ‘profit’ for you :(
{end}

Sum of profit from direct relations:

{relation.managers_loyal.direct.profit.total}

Editor Functions

Price Formatting

Use this function to separate numbers into groups of three digits with a chosen separator.

Price 8.000 RUR
<p>Price {format json.price "."} RUR</p>

Access it via </>Output FunctionsFormatting.

Date Offset

The function adddate(date, year, month, day) returns a new date with the added interval.

<p>Event starts on {adddate(lead.notify_date 0 0 10)}</p>

It can be used inside format():

<p>Event starts on {format adddate(lead.notify_date 0 0 10) "%Y-%m-%D"}</p>

Access via </>Date and TimeDate Offset.

Date Formatting

To format dates based on regional preferences, use this:

<p>Birth date {format lead._bdate "%D.%m.%Y"}</p>

Supported date formatting options:

# years
"%y": "06"
"%Y": "2006"
"yy": "06"
"YYYY": "2006"

# months
"%m": "01"
"MM": "01"
"%B": "January"
"month": "January"
"%ru_month": "январь"

# days
"%d": "2"
"%D": "02"
"DD": "_2"
"%A": "Monday"
"weekday": "Monday"

# hours
"%H": "15"
"%I": "3"
"hh": "15"
"hours": "15"
"twelve_h": "3"

# mins
"%M": "04"
"mm": "04"

# seconds
"%S": "05"
"ss": "05"

# am/pm indicator
"am": "pm"
"AM": "PM"
"%p": "pm"

# timezone
"tzone": "-07"
"timezone": "-07:00"
"%Z": "Z0700"

If using external JSON content, Altcraft can parse RFC 3339 strings into datetime:

ModeFormat
JSON"date_time": "2023-02-21T11:10:35.141Z"
Template{format apicontent.date_time "%Y-%m-%d %H:%M:%S"}
Preview2023-02-21 11:10:35

Access via </>Date and TimeFormatted Date.