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

<figure><img src="/files/GX7hTuM4GdDY4FerHJSf" alt=""><figcaption><p>Creation of a label tag</p></figcaption></figure>

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

<figure><img src="/files/2YceB1ag1iPhSZ5Qgn9n" alt=""><figcaption></figcaption></figure>

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.

<figure><img src="/files/hVzbH4FzU2rU5TvQT8fR" alt=""><figcaption></figcaption></figure>

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

{% code overflow="wrap" %}

```javascript
(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());
})()
```

{% endcode %}

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

```javascript
(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

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

#### Tag with parameters

In some cases, you might need to build a tag that accepts a parameter.\
\
For example below function is calculating an final amount based on base amount and user currency. In order this to happen we need base amount as parameter and user currency which we fetch from the user state property (label tags are supporting tag replacement).

```
function(amount) {
    var amt = (typeof amount !== 'undefined' && amount) ? amount : 0;
    var curr = (state && state.core_wallet_currency) ? state.core_wallet_currency : "EUR";
    var mult = 1;
    if (curr === 'AUD' || curr === 'CAD' || curr === 'NZD') {
        mult = 1.5;
    } else if (curr === 'USD' || curr === 'EUR') {
        mult = 1;
    } else {
        mult = 1;
    }
    return (amt * mult);
}
```

Here is an example on how the above label tag should be inserted: {{label.cash\_bonus(15)}} (in this case 15 will be send to the function as amount parameter).

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

<figure><img src="/files/tgQWbF43K9OQOPoJ6iW1" alt=""><figcaption></figcaption></figure>

2. Choose Tag Name
3. Choose tag value type - JavaScript Function
4. Paste the JavaScript code below:

```javascript
(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;
})()

```

5. Set your own Secret Key - replace `MY_SUPER_SECRET_KEY` with your own secret key.
6. Set Token expiration
   1. 3 hours example - `exp: now + 3 * 60 * 60 // +3 hours`
   2. 10 minutes example - `exp: now + 10 * 60 // +10 minutes`\ <br>
7. 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

<figure><img src="/files/KSfrDnjUibG8H0T9Ds7A" alt=""><figcaption></figcaption></figure>

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

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.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://help.smartico.ai/welcome/products/general-concepts/label-tags.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
