Skip to main content

Altcraft variables and functions

Customer profile variables

Profile data variables
DescriptionVariable
Email address{lead.email}
Phone numbers{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}
Customer ID{lead._id}
XXM-hash{lead._xxm}
XX-hash{lead._xxh}
MD5-hash{lead._md5}
*Extra field{lead.field_name}
Profiles subscriptions variables
DescriptionVariable
Subscription email address{subscription.email}
Subscription email domain{subscription.email_domain}
Subscription email addresses list{subscription.emails}
Subscription phone number{subscription.phone}
Subscription phone numbers list{subscription.phones}
Push subscriptions list{subscription.pushes}
Email address MD5 hash{subscription.email_md5}
Phone number MD5 hash{subscription.phone_md5}
Subscription hash{subscription.hash_id}
Custom subscription field{subscription_field("channel" "field_name" resource_id)}

channel - a string indicating the channel ("email")
field_name - the name of the field to insert ("domain")
resource - resource identifier(10)

The subscription_field function allows you to insert fields from subscriptions, regardless of the channel used in the current message. For example, if a profile has an SMS subscription, you can substitute its phone number in the email version of the message: {subscription_field("sms" "phone")}.

If more than one subscription matches the conditions, the platform selects the subscription with the highest priority.

Available fields for substitution:

ChannelFieldDescription
emailemailSubscription email address
domainSubscription email domain
domain_groupDomain group
md5Email address MD5 hash
smsphoneSubscription phone number
md5Phone number MD5 hash
pushsubscription_idPush subscription ID
bundle_idApp ID for iOS APNs
providerPush provider
tip

In the same way, you can substitute data from custom channel subscriptions into the template. The fields of custom channels correspond to the sid of the fields that you specify when creating the channel.

Profile relations

General variable formula:

{relation.[short_relation_name].[direct or reverse].[property_name].[count, total, top]}

The number of direct relations with the "profit" property:

{relation.managers_loyal.direct.profit.count}

Top of the reverse relations with the "profit" property. A loop is used to output multiple values:

{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}

The sum of the "profit" property value for the direct relation:

{relation.managers_loyal.direct.profit.total}
Date and time variables
DescriptionVariableExample
Formatted date{format}{format datenow "%Y-%m-%D %H:%M:%S timezone, %I am"}

2018-12-24 18:56:10 +03:00, 6 pm
Unformatted date{datenow}2018-12-24T18:56:10+0300
Date shift{adddate()}{adddate(datenow 0 0 3)}

2018-12-27T18:56:10+0300
Full year{yearlong}2018
Year{year}18
Month{month}12
Day{day}10
Hours in 24-hour format{hours}18
Hours in 12-hour format{hours12}06
«A. M.», «P. M.»{ampm}PM
Minutes{minutes}56
Seconds{seconds}10
Extra variables
DescriptionVariable
API content{apicontent.field_name}
SMS sender name{from_name_sms}
Pixel for letter opening tracking{pixel}
Pixel for letter reading tracking{read}
Resource ID{resid}
Database name{listname}
Database ID{listid}
Message name{msgname}
Message ID{msgid}
Message type{msg_type}
Message sending cancel{cancel}
Tracking domain{trkdomain}
Campaign name{campname}
Campaign ID{campid}
Campaign SUBID{subid}
Adding to the suppression list{suppress}
Subscription manager URL{preferences}
Unsubscription URL{unsubscribe}
Global unsubscription URL{globalunsubscribe}

Editor functions

Date formatting

Information of "date" type have different display in different countries. For subscribers convenience there is date formatting function.

For example, to display subscribers birth date as:

Date of Birth 02.11.1998

You can use this function:

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

All examples of date formatting:

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

# months
"%m": "01"
"MM": "01"
"%B": "January"
"month": "January"

# 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"

To insert a function, press </> button in template editor and select Date&time → Formatted datetime.

Date shifting

adddate(date, year, month, day) function returns date value after it adds certain interval to it.

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

adddate() can be used inside format() function.

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

To insert a function, press </> button in template editor and select Date&time → Date shifting.

Price formatting

Also, there is function of number data format, which divides number to blocks by three digits using selected delimiter.

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

To insert a function, press </> button in template editor and select Output functions → Format.

Encryption and hashing

If you want to send template content and variables in encrypted or hashed type, you can use crypt function in the templates editor. To use it, press </> button in the templates editor and select Encryption.

You can change coding or encrypt data using one of these algorithms:

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

For sha1 and sha256 you can add salt. For AES and Blowfish you can use key in base64 coding as salt.

AES and Blowfish encryption details:

AESBlowfish
Initialization vectorFirst 16 bytes of the stringFirst 8 bytes of the string
Encryption modeCFB (Cipher Feedback)CBC (Cipher Block Chaining)
Key length128 bits — 16 symbols64 bits — 8 symbols
Paddingnullnull
tip

Encryption / decryption is done via Base64URL encoding.

Below, there are syntax examples for changing coding and encryption.

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

If you want to encrypt one line of text, you need to put it into quotes. If it is number, you do not need to use quotes:

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

These algorithms are available for hashing. You can use salt for each of them:

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

They use same syntax like encryption functions:

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

Note that the encrypted data will already be encoded in base64.

Output functions
DescriptionVariableExample
Formattingformat{format 1000000000 ","}

1,000,000,000
Variable lengthlength{length("abc")}

3
Arrayarray{array[1 "2" 3.3]}

[1 2 3.3]
Random array elementrandomize{randomize(array[1 2 3])}

1
Array limitlimit{limit(array[1 2 3] 2)}

[1 2]
Even numberiseven{iseven(2)} => true

{iseven(3)} => false
URL-address codingurlencode{urlencode(lead._regurl)}

http:%2F%2Ftest.testdomain.com%2Fsomething

Used to encode unsupported characters in URL parameters.
URL-address decodingurldecode{urldecode(lead._regurl)}

http://test.testdomain.com/something
Uppercaseuppercase{uppercase("text")}

TEXT
First character in uppercaseuppercasefirst{uppercasefirst("john")}

John

Logical expressions

info

Using logical expressions in described in a dedicated article.

This construction is used to create the simplest condition:

{if lead.age gte 18}
If 18 years and older.
{else}
If younger than 18.
{end}

Loops

info

Using cycles is describes in a dedicated article.

External JSON

Market variables

Fragments

info

Using fragments is described in a dedicated article.

To insert a fragment, use {fragment.<fragment_short_name>}

To insert a random fragment from a set range: {randomfragment[fragment.name1 fragment.name2 fragment.name3]}

JSONPath

info

The JSONPath query language allows you to quickly and easily access JSON objects from dynamic content source.

The JSONPath variable on the Altcraft platform is specified as follows: {jsonpath(json.<root_object> "<path_to_object>" "<output_format>")}

The usage of JSONPath functionality is described in this article.