▪️Activity: JS Code
Activity "JS Code" provides possibility to execute custom JavaScript code in the browser of the user that is online.

Important to note that in order to be executed, the user should be online on your side, so the activity should be triggered when you are confident that user is on site, for example you can use "Wait for event" with event "User went online", or product specific activities that are done on the web site, e.g. deposit, request for withdrawal, bet, etc.
You can also use "Delivery timeout", in order to overcome cases when user went offline for some period of time, by default 20 seconds. For example:
You build a campaign that is triggered on the first login during the day and is supposed to execute some JavaScript code.
There is a chance that right after login, the user is redirected to another page, which means that he was "offline" for a short period of time while navigating to another page.
Delivery timeout is supposed to handle such cases and deliver the JavaScript code to the user the next time they are online within the defined period.
Activity Configuration and Outcomes
When adding a JS Code activity to a Campaign Flow, configure the following fields:
JavaScript code to execute: The JavaScript snippet to run in the user's browser.
Delivery timeout: The time duration (default: 20 seconds) the system will wait for an offline user to reconnect before marking the execution as timed out.
The activity provides the following connection outcomes in the Flow Builder:
Executed: Triggered when the JavaScript snippet finishes executing in the user's browser without throwing an error.
Failed: Triggered when the script throws an uncaught JavaScript error in the browser or when the delivery timeout expires while the user is offline.
Some ideas of what you can do with "JS Code"
Dynamic Tag Replacement
Smartico resolves dynamic tags (such as user attributes, label tags, and event parameters) before sending the JavaScript code to the user's browser.
You can insert tags like {{user.username}} or {{event.amount}} directly inside your script. When assigning text values to JavaScript variables, enclose the tag in quotation marks (for example: const player = "{{user.username}}";) so the substituted value forms valid JavaScript syntax.
Use own JavaScript methods, for example trigger opening of the deposit page
Use 3rd party libraries APIs, e.g. trigger an event in the Google Analytics or start browser screen recording with HotJar or with Microsoft Clarity, or mark conversion with FaceBook AD API.
Use Smartico front-end API (extended integration) to trigger different actions, for example to change an avatar of user -
_smartico.setAvatar("https://somesite.com/avatar.png");Use Smartico front-end API to do any actions with gamification setup, for example register in the tournament when user does a deposit with code like
_smartico.api.registerInTournament(12345)or opt-in user in the specific mission with code like_smartico.api.requestMissionOptIn(12345)
Frequently Asked Questions
What is the difference between the JS Code flow activity, JS Injection in Label Settings, and Label Tag JavaScript functions?
JS Code activity: Executes in the user's browser in real time when reached during a Campaign Flow.
JS Injection (Label Settings): Executes once in the browser on page load when the Smartico script initializes on your website.
Label Tag JavaScript functions: Evaluated on the server to generate dynamic text values for tags and templates; they do not have access to browser objects such as window or document.
What happens if a user is offline when the JS Code activity runs?
The code delivery remains pending until the user comes online or until the configured Delivery timeout expires. If the timeout expires before the user connects, the activity fails with an execution timeout and continues down the Failed branch.
Can I update user profile properties directly from the JS Code activity?
To update player attributes from a campaign flow, use the dedicated Update Property flow activity. If you need to trigger updates from client-side JavaScript, use the front-end profile update methods for allowed properties.
Last updated
Was this helpful?