Sites without authentication

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

You still have to provide user information, Product Fruits won't work without it. You can generate a random username, store in in browser's localStorage and use it later.

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.

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 billing 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 logged-in user. Then you can use segmentation and (don't) display the content.