Doofinder logo

Support Documentation

Search icon

Show Products Only To Specific Users

By leveraging the capabilities of the Doofinder Script, you can effectively manage and personalize the visibility of your product catalog for different user groups. This approach involves three key steps: indexing an attribute for product visibility, implementing dynamic variables for user group identification, and modifying the Doofinder Script to apply these variables.

You can dynamically filter/exclude search results directly from the Doofinder Script.

Filter

      const dfLayerOptions = {
        installationId: "xxx-xxx-xxx-xxx",
        zone: 'xxx',
    params:{
    "":{
    filter: {
      attribute: ["value"]
    }
    }
    }
      };

Exclude

You could also exclude a specific attribute/value using the following parameter:

    params:{
    "":{
    exclude: {
      attribute: ["value"]
    }
    }
    }

Here, for example, we will filter the search results, so only the category "visible" will return results:

      const dfLayerOptions = {
        installationId: "xxx-xxx-xxx-xxx",
        zone: 'xxx',
    params:{
    "":{
    filter: {
      category: ["visible"]
    }
    }
    }
      };



      (function (l, a, y, e, r, s) {
        r = l.createElement(a); r.onload = e; r.async = 1; r.src = y;
        s = l.getElementsByTagName(a)[0]; s.parentNode.insertBefore(r, s);
      })(document, 'script', 'https://cdn.doofinder.com/livelayer/1/js/loader.min.js', function () {
        doofinderLoader.load(dfLayerOptions);
      });

Different user groups

If you have different user groups, with specific rules to access the product catalog, follow these steps:

  1. Index an attribute for product visibility
  2. In your product data feed, you will need to index an attribute, indicating the visibility to your user groups, for each product. Let's take the following case, for which we have three different user groups: A, B, and C.

    We index the following attribute:

    • "available_for_groups": "A/B/C" // this product is available for groups A, B, and C
    • "available_for_groups": "A/C" // this product is available for groups A and C

  3. Implement dynamic variables for user group identification
  4. Next up, it's time to integrate dynamic variables into your HTML code to distinguish between user groups. Align these variables with the "available_for_groups" attribute in your feed, ensuring seamless coordination between the two. It is required that both the values of this dynamic variable and the values of the "available_for_groups" attribute in your feed share the same values.

    For instance, in your product data feed, index the attribute as follows: A

    In your HTML code, create the corresponding variable: let dfGroupFilter = "A"

    In our example, dfGroupFilter can take the value “A”, “B” or “C”

  5. Modify the Doofinder Script
  6. In our example:

    • the attribute indexing the values for which the product is available is named "available_for_groups".
    • the variable identifying the user group from your HTML code is named "dfGroupFilter".

Here is what the Doofinder Script would look like:

      const dfLayerOptions = {
        installationId: "xxx-xxx-xxx-xxx",
        zone: 'xx',
    params:{
    "":{
    filter: {
      available_for_groups: [dfGroupFilter]
    }
    }
    }
      };



      (function (l, a, y, e, r, s) {
        r = l.createElement(a); r.onload = e; r.async = 1; r.src = y;
        s = l.getElementsByTagName(a)[0]; s.parentNode.insertBefore(r, s);
      })(document, 'script', 'https://cdn.doofinder.com/livelayer/1/js/loader.min.js', function () {
        doofinderLoader.load(dfLayerOptions);
      });

Conclusion

This method ensures that only the appropriate products are shown to the corresponding user groups, enhancing user experience and maintaining the integrity of your product visibility rules. By following these steps, you can create a more tailored and secure shopping experience environment for your users.

Did you find this page helpful?