Label tags

Label Tags are different from the user state tags (such as game played, favorite team, etc), with Label Tags you can easily create your own tags in the system, with your own content.

General concept

There are 3 types of label tags - Static text, JavaScript function, and JS function with parameters. Here's one example of how to use a 'Static text' label tag: Create an email template to welcome your users to their new VIP level; Following that, we will have to create the respective Label Tag. Create a welcome_to_vip Label Tag and provide a default value.

Creation of a label tag

Define the different conditions for each of the players' VIP levels and provide content.

Insert {{label.welcome_to_vip}} label tag in your email body and each VIP user will get their welcome message.

Steps to create a Label tag

  1. Go to the Tools tab on the top menu

  2. Select Label tags from the “Main” section

  3. Click on +Create

  4. Select type - Static text, JavaScript function, or JS function with parameters

  5. Choose the Tag name (i.e. welcome_to_vip)

  6. Put the Tag value (i.e. Welcome to VIP Bronze/Silver)

  7. Choose the conditions for which users this tag will be affecting You can choose a few conditions, like Language, VIP level, Country, specific username, and any property available in our core, and in your product.

Dynamic label tags

In some cases, you need to build a label tag that changes over time.

The most common case is to show a date that is relative to the time when the end-user is getting a communication message, e.g. to build a communication like "The promo code is valid till Jan 15, 2019".

For this need, you can use a Label tag with the type "JavaScript function" and put the code to build dynamic content.

A tag showing the current date

Example of the label tag that builds a date in 4 days from now in the format "15.01.2019"

(function() {
	var Calendar = Java.type('java.util.Calendar');
	var date = Calendar.getInstance();
	date.add(Calendar.DATE, 4);
	var Format = Java.type('java.text.SimpleDateFormat');
    var formatter = new Format("dd.MM.YYYY");
    return formatter.format(date.getTime());
})()

Tag returning different images based on the current day of the week

(function() {
    return [
    	"https://mycdn.com/sunday.png",
    	"https://mycdn.com/monday.png",
        "https://mycdn.com/tuesday.png",
        "https://mycdn.com/wednesday.png",
        "https://mycdn.com/thursday.png",
        "https://mycdn.com/friday.png",
        "https://mycdn.com/saturday.png"
    ][new Date().getDay()]
})()

Tag returning current day of the week in English

(function() {
    return [
    	"Sunday",
    	"Monday",
    	"Tuesday",
    	"Wednesday",
    	"Thursday",
    	"Friday",
    	"Saturday"
    ][new Date().getDay()]
})()

Auto-login with JWT in the email communication

You can easily create a secure, token-based authentication mechanism for users clicking on links within communications sent via Smartico CRM, leveraging JSON Web Tokens (JWT).

The method allows for temporary, self-contained authentication without exposing sensitive credentials. Adopting this feature will allow you to send secure, personalized email links that automatically log your users into their accounts upon clicking, significantly improving user experience and security posture.

Steps to create:

  1. Go to BO > Tools > Label tags > Create JavaScript Function

  1. Choose Tag Name

  2. Choose tag value type - JavaScript Function

  3. Paste the JavaScript code below:

(function() {
    var Base64 = Java.type("java.util.Base64");
    var Mac = Java.type("javax.crypto.Mac");
    var SecretKeySpec = Java.type("javax.crypto.spec.SecretKeySpec");
    var StandardCharsets = Java.type("java.nio.charset.StandardCharsets");
    var secretKey = "MY_SUPER_SECRET_KEY";
    function base64UrlEncode(bytes) {
        return Base64.getUrlEncoder().withoutPadding().encodeToString(bytes);   
    }
    var header = { alg: "HS256", typ: "JWT" };
    var now = Math.floor(Date.now() / 1000);
    var payload = {
        sub: String(state.user_ext_id_clean),
        iat: now,
        exp: now + 3 * 60 * 60 // +3 hours 
    };
    var headerB64 = base64UrlEncode(JSON.stringify(header).getBytes(StandardCharsets.UTF_8));
    var payloadB64 = base64UrlEncode(JSON.stringify(payload).getBytes(StandardCharsets.UTF_8));
    var signingInput = headerB64 + "." + payloadB64;
    var mac = Mac.getInstance("HmacSHA256");
    var secretKeySpec = new SecretKeySpec(secretKey.getBytes(StandardCharsets.UTF_8), "HmacSHA256");
    mac.init(secretKeySpec);
    var signatureBytes = mac.doFinal(signingInput.getBytes(StandardCharsets.UTF_8));
    var signatureB64 = base64UrlEncode(signatureBytes);
    return signingInput + "." + signatureB64;
})();
  1. Set your own Secret Key - replace MY_SUPER_SECRET_KEY with your own secret key.

  2. Set Token expiration

    1. 3 hours example - exp: now + 3 * 60 * 60 // +3 hours

    2. 10 minutes example - exp: now + 10 * 60 // +10 minutes

  3. Create your email Template and use the tag in the link to your web site, for example, using the button in the mail editor - https://yourwebsite.com/login?jwt={{label.test_jwt_100001}} Replace the {{label.test_jwt_100001}} in the link with the Label tag you have created

  1. Send emails (or any communications) to users or Create campaigns with Emails, choosing the Template you created.

On you website you will need to handle "jwt" parameter, decode it with the secret key and after extracting user_ext_id_clean, do a login for this user.

Last updated

Was this helpful?