Sites without authentication

Product Fruits works best after login. But if you want to implement Product Fruits to a site without authentication or before login, it is possible.

You still have to provide user information, Product Fruits won't start without a username. You can generate a random username, store in in browser's localStorage and use it later. It's also possible to hardcode a username but this will result in onboarding content that is only intended to show 'once per user' will not function properly.

This is an example of the username generator:

function makeid(length) {
	let result = '';
	let characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
	let charactersLength = characters.length;
	for (var i = 0; i < length; i++) {
		result += characters.charAt(Math.floor(Math.random() * charactersLength));
	return result;

let generatedUserName = localStorage.getItem('user');
if (!generatedUserName) {
	generatedUserName = makeid(8);
	localStorage.setItem('user', generatedUserName);

Later, when you initialize Product Fruits, use the generatedUserName variable for the username field of the Product Fruits user info object.

If the user logs in later and there is no reload (the login form and the following page work as a single page), call productFruits.identifyUser({ username: '<<REPLACE>>' }) to re-identify the user.

Please note, that using Product Fruits on sites without authentication can cause some of these situations:

  • Users can see the same content multiple times as they can use different browsers or they will delete their browsing data.
  • Because of the previous issue, your monthly active user count might go over your quota, because one user can be tracked as multiple users.
  • When the user logs in, the same content can show again, because the user will be seen as a new user by Product Fruits. A potential solution to this issue might be using a custom property saying if it is an anonymous user or a logged-in user. Then you can use segmentation and (don't) display the content.