1. Decision table inputs

Create custom values

Custom values let you create your own JavaScript-based logic for component personalization.

Unlike profile data or conditions, custom values can combine profile attributes, visitor behavior, and custom logic into a single value that you can use as an input in decision tables for audience targeting.

You can create custom values manually or generate the JavaScript with the Code Assistant.

Create a custom value using JavaScript

If you are familiar with JavaScript, you can create a custom value manually by writing your own logic in the code editor.

To create a custom value manually:

  1. On the Custom Values page, click Create.

  2. Enter a name for the custom value.

  3. Click Create.

  4. In the code editor, enter or edit the JavaScript for the logic you want to use.

    For example, the following custom code returns the lastPage value from the visitor’s most recent session:

    (function() {
      if (!profile || !Array.isArray(profile.sessions) || profile.sessions.length === 0) {
        return null;
      }
    
      const latestSession = profile.sessions[0];
      if (!latestSession.stats || typeof latestSession.stats.lastPage !== 'string') {
        return null;
      }
    
      return latestSession.stats.lastPage;
    })()
  5. On the Overview tab in the right pane:

    • Enter a short description for the custom value.

    • Select or create tags to help organize and identify it.

    • Select the Return type, such as String, Number, Boolean, Date, or Array.

  6. Click Save.

Create a custom value with the Code Assistant

If you are not familiar with JavaScript, you can use the Code Assistant to generate a custom value from a natural language prompt.

To create custom data with the Code Assistant:

  1. On the Custom Values page, click Create.

  2. Enter a name for the custom value.

  3. Click Create.

  4. In the Code Assistant pane, do one of the following:

    • Enter a prompt describing the logic you want to create.

      When writing prompts, be specific about visitor attributes, time frames, conditions, and the expected return value.

      Example prompts:

      • Return true if the visitor’s birthday is within the next seven days.

      • Categorize visitors as high, medium, or low intent based on session count and page views.

      • Return true if the visitor viewed more than five product pages.

    • Select one of the suggested prompts.

    The Code Assistant generates JavaScript based on the current prompt and any code already in the editor.

    Note

    AI-generated responses can vary. Running the same prompt multiple times may produce different results.

  5. To preview the generated code, click View.

  6. In the dialog:

    • Click Replace code to insert the generated code into the editor.

    • Click Copy code to copy the generated code to your clipboard.

    Important

    AI-generated code may not always be accurate. Always review and test the generated code before using it.

  7. Optionally, after inserting the code:

    • Make manual changes in the code editor.

    • Click Undo to revert changes.

  8. Click Save.

Next steps

After saving the custom value:

If you have suggestions for improving this article, let us know!