Trust ID is a JS client library to work with user identification for web applications.
npm install @digica/trust-idTrust ID is a JS client library to work with user identification for web applications.
If your application uses a bundler or node.js, you should install TrustID by npm/yarn/pnpm:
``bash`
npm install @digica/trust-id
Now you can use TrustID in your application:
`js
// CommonJS
const { TrustID } = require('@digica/trust-id');
// or ESM
import { TrustID } from '@digica/trust-id';
// Create instance of TrustID class and initialize
const trust = new TrustID({ publisherId: 42 });
`
If you don't use a bundler or node.js, you can load TrustID from CDN:
`html`
src="https://unpkg.com/@digica/trust-id"
async
>
src="https://cdn.jsdelivr.net/npm/@digica/trust-id"
async
>
After installation and initialization, Trustid is ready for use. The first step is to decide where to look for the user identifier. There are three ways to do this:
1. Get textContent of DOM element
2. Get value of URL query parameter
3. Execute a callback in any place of your application
You should provide the ID of DOM element that you want to get the user identifier from. It'll be observed for changes, and when the element appears in DOM, the textContent of the element will be processed by library.
`html`
You should provide the name of the URL query parameter where you can find the user identifier. The library will observe the change in the parameter, when it appears in the URL, the value will be processed by the library.
`html`
You can execute the callback function in any place of your application by yourself, and pass the user identifier as a parameter.
`html`
id="send-user-identifier-button"
data-user-id="+79999999999"
>
Send user identifier
All the above methods can be used in web applications.
`jsx
import { TrustID } from '@digica/trust-id';
// Create instance of TrustID, initialize and export it for access from other components
// You don't have to execute "init" method, just pass config in constructor
export const trust = new TrustID({ publisherId: 42 });
function App() {
const [userIdentifier, setUserIdentifier] = useState('');
const handleButtonClick = () => {
trust.setUserIdentifier(userIdentifier);
};
return (
Debug mode
There isn't any debug logs by default, but you can turn them on by setting
debug option to true in initialization. After that, you can see logs in your browser console.`html
``