π₯οΈInstall SDK
Reach out to the script page and choose between vanilla JavaScript snippet or the one thought for frameworks. Letβs see each of them in detail.
JavaScript
The vanilla JavaScript installation is right before the closing </body>
tag of your application.
Frameworks
If you donβt have direct access to the HTML code (when using a framework like Next.js), you can use the framework snippet instead of the JavaScript one.
π‘ This script can also be used in projects that have access to the HTML code, but since it is more verbose, the other option is recommended. However, there are some valid use cases, for example, if you canβt access the user data in the HTML (because is stored in Redux for example).
In this case, the script should be installed at the root of your project or in the component that is rendered on every page. In react, that would be in the App.js file for example (or the _app.js file in Next.js).
More complex installations
There are some times when the installation can be more difficult because the user data is not available in the root component (for example because is stored in a redux container that is initialized in an inner component).
Letβs take for example the case of a Next.js application. Imagine that in that case the user data is fetched in a react context.
In this case, you cannot just introduce the snippet here
Because the <UserProvider />
that is the one with the data in an inner component we cannot call the Trackey popup here.
To solve this, our recommendation is to create a subcomponent and put it inside the <UserProvider />
so that it has access to the user data through the useUser()
function that is exported by it.
What data do I need to introduce in identifyUser?
In the identifyUser you should pass the data of the user that is currently logged into your application. So, letβs take for example that a user signs into your application with the email john@acme.co. Internally you would usually generate a unique id for this user, for example, 1234.
The identifyUser function would look like this:
Obviously, you will never hardcode the data in the function, you would instead introduce it through a variable.
Letβs say that in your front you store the data in a userData variable, in that case, the code will look like this:
User Properties
In addition to the userId and email fields that are required, you can include more user properties, that will be used inside of Trackey to create segments. For example, letβs consider that you also store in the previous userData function the payment plan variable(free trial, basic, pro, enterprise, β¦). You can include that data in the popup just by adding it below the other two.
More detail about this topic can be found in our technical documentation.
More info
A complete description of the popup capabilities can be found in our technical documentation.
Last updated