Installation
In your web application, it is necessary to install our Web SDK so that the entire flow is tracked and attributed correctly. For this, you need to include the Nemu pixel script in the <head> of all your web pages. The Nemu pixel can be created in your dashboard by going to: Integrations -> Pixels -> Click here to add
See how to install here
At the end of creation, the URL of the Nemu pixel script will be displayed. Copy and paste it into the <head> of all your site pages.
With this, the global variable trackingNemu will be available with utility methods for tracking.
Registering UID to the user session
For total security and integrity of your application user data,
all UIDs registered by our SDK are encrypted before being
stored on our servers.
During the application login process, add a call to the setUserId() method, passing the defined UID of the user who just completed the login process as an argument. Example:
function authenticateUser() {
const email = "user@example.com";
const password = "1234";
loginUser({
email: email,
password: password,
onSuccess: function (userId) {
trackingNemu.setUserId(userId);
console.log(`NemuTracking: Registered user: ${userId}`);
},
onError: function () {
console.error("NemuTracking: Failed to authenticate user");
},
});
}
It is mandatory to ensure that users who were already logged in before the SDK installation or update are also correctly tracked.
To do this, you can define the UID as soon as it is available in the application, normally right after loading the locally saved user.
Common options in web applications would be:
SPA App: inside the global loading useEffect
Common Sites: right after the SDK script loads, if window.user is already available
const userId = window.sessionUser?.email || window.sessionUser?.id;
if (userId) {
nemuTracking.setUserId(userId);
}
Retrieving UTMs when sending sale event to Nemu API
The getLastSessionHistory() method returns an object containing the UTMs from the user’s last session. Use this object when sending the sale information to the Nemu API.
function sendSaleWithUtms() {
const session = trackingNemu.getLastSessionHistory();
if (!session) {
console.log("No sessions found");
return;
}
const payload = {
transactionId: "123",
netValue: 10,
status: "paid",
utm_campaign: session.utmCampaign ?? null,
utm_content: session.utmContent ?? null,
utm_medium: session.utmMedium ?? null,
utm_source: session.utmSource ?? null,
utm_term: session.utmTerm ?? null,
};
const url = "https://developers.nemu.com.br/api/v1";
fetch(url, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(payload),
})
.then((response) => {
console.log(`API response: ${response.status}`);
})
.catch((error) => {
console.error(`Error to send: ${error.message}`);
});
}