Segmentation and custom data

Segmentation is a powerful tool for displaying different content to different users. Product Fruits can use your application's data to target the right cohorts.

Custom data

When you integrate our JavaScript snippet, you can also provide different user data. This will allow you to use them for segmentation rules or as placeholders in your content.

This is how you can provide custom data:

const productFruitsUserData = {
   username: '', // the unique user ID, this property is required
   email: '', //
   firstname: '',
   lastname: '',
   signUpAt: '',
   role: '',
   
   /* CUSTOM DATA STARTS HERE */
   props: {
      customProperty1: '',
      customProperty2: 123,
      customSubObject: {
          myOtherProperty: true
      }
   }
}

As you can see, besides the predefined properties like username, first name, etc., you can also include the props field and insert any custom data you need.

React, NextJS

The user information has to be provided as props to our React component.

<ProductFruits projectCode='...' language='en' {...productFruitsUserData} />

Standard JavaScript snippet

Assign the variable to the window.productFruitsUser variable before the JavaScript snippet is executed. Do not change this variable after the Product Fruits snippet is initialized. If you want to change the user data later, use the productFruits.identifyUser({...}) method.