▪️Secure identification and special setups
This page explains how to protect player identification with a hash, how to open the Gamification widget from your own back office, how to integrate when your site runs inside an iframe, and how to test on localhost.
Protecting user identification on the public front-end
The simple user identification is based on the unique ID of the user set in the _smartico_user_id
<script>
window._smartico_user_id = 'some_id';
window._smartico_language = 'fr';
</script>In case the user ID can easily be guessed (e.g. it's a sequential number or just a string that corresponds to the username), there are additional mechanics to protect identification.
You will need to calculate a hash string from the user ID, secret salt key, and validity timestamp. The calculation formula is the same as described here. The hash should be calculated on the server(!) and passed in the front end in the following way. For the Smartico script, Smartico checks the hash against the user ID in lower case, without spaces at the start and end, so build the hash from the user ID in the same form (for example ABC123 → abc123). The public HTTP API checks the hash against the user ID exactly as you send it.
<script>
window._smartico_user_id = 'some_id';
window._smartico_language = 'fr';
window._smartico_user_hash = '019b370929095f0cfe6c9b02ea7524a2:1638050700000';
</script>The salt key should be requested from Smartico Customer Success Manager and should be kept in secret. The check is enforced when the Require a signed hash to identify players setting in Label settings is on. Turn it on only after your site sends the hash: without a valid hash the user is not identified.
Opening gamification widget from operator's backoffice
The gamification widget can be opened in read-only mode from 3rd party sites.
The most common reason for this is to provide the Support team the possibility to see the current status of the gamification setup as the end-user sees it.
The widget can be opened using the URL:
Parameters to be passed:
label_key & brand_key - the same set of public keys for the label & brand as used in the front-end integration for the end user
user_ext_id - identification of the user in the integrated product
user_hash - md5 hash and the validity timestamp separated with the ":" symbol
The user_hash should be calculated in the following way
Label salt key can be retrieved from label configuration in Smartico BackOffice (the Secret 'salt' key setting in Label settings). Hash validity timestamp is defining the time in epoch with milliseconds till which the hash will be valid. A hash whose timestamp has passed is rejected. Write the MD5 value in lower-case hex, as in the example below.
Example of calculation:
Example of JavaScript code opening a widget in the iframe and closing it when the widget is closed from inside:
Smartico BackOffice is using the same approach to show the gamification widget of any user in the CRM section

IFrame bridge (B2B)
If the integrated platform is loaded in the iframe and not the owner of the main window, the setup should be done in a different way.
The site that owns the main window should load only the Smartico script without doing initialization of the label/brand and identifying the user. HTML code to paste as is:
The iframe should load smartico_inframe.js script and makes the same calls as described in Front-end integration and the other Extended integration pages, but using _smartico_inframe object instead of _smartico.
Only these methods are available on _smartico_inframe: dp, init, identify, online, login, logout, changeLanguage, event, action, setAvatar, miniGame and suspendPopups. The main window ignores other calls. It also accepts calls only from an iframe placed directly on its page, not from a nested iframe or a separate window.
Example of the script
Debug/develop on the localhost
By default, the Smartico script is not allowed to be used on the localhost.
This is done to prevent the creation of "phantom" users when the script running on localhost is usually connected to the DEV/QA environment, and the user that reported from this environment will be sent to Smartico, which will lead to the creation of the users that shouldn't be on production.
If you want to run on localhost and you are going to use a real/production user, you can enable debugging on the localhost
The Domains where the Smartico script may run setting in Label settings limits the domains where the script identifies the user. Enter a comma-separated list of domains, for example mobile.mysite.com,mysite.com. A domain matches when the site address ends with it, so mysite.com also matches another-mysite.com. On other domains the script does not identify the user. When the setting is empty, the script works on any domain except localhost. You can also set it for one brand, on the Brand settings tab of that brand.
To allow localhost without the flag above, add localhost to this list, together with your real domains.
Frequently Asked Questions (FAQ)
How do I configure user identification protection with a Salt Key?
To protect against user identification tampering on the front end, request a secret salt key from your Customer Success Manager or obtain it from Label Settings in the Back-Office (the Secret 'salt' key setting). Enable the setting Require a signed hash to identify players in Label Settings.
On your backend server, generate an MD5 hash using the external user ID, the secret salt key, and an expiration timestamp (milliseconds since epoch, e.g. valid for 24 hours):
MD5(user_id + ":" + salt + ":" + timestamp) + ":" + timestamp
Pass this value on the front end as window._smartico_user_hash or via the identification method. Keep the salt key exactly as it is. For the Smartico script, use the user ID in lower case, without spaces at the start and end, because Smartico checks the hash against the user ID in this form. Write the MD5 value in lower-case hex.
Last updated
Was this helpful?