How to Use Segments


Demandbase Segments

The Demandbase.Segments class evaluates all defined Conditions and Segments and makes them available as easy-to-use Boolean properties of the Demandbase.Segments class. This example shows using segments to set variable in a JavaScript condition:

if(Demandbase.Segments.EnterpriseSegment) {
    imgUrl = 'enterpriseURL.jpg';
} else if (Demandbase.Segments.SMBSegment) {
    imgUrl = 'smbURL.jpg';
} else {
    imgURL = 'defaultURL.jpg';

Basic Definitions


A "Condition" is a comparison of a Demandbase attribute and a specific value or an list of values. Think of Conditions as the building blocks for Segments. A 'Condition' that does not have the standalone attribute set to false will also be a "Segment". Any number of Conditions can be used to define a Segment.


A "Segment" is a business rule, a Boolean combinations of Conditions (or the evaluation of a single Condition) surrounding a visitor's company profile.

Configuring Conditions and Segments

The Demandbase.Segments class houses an array of DBCondition objects and an array of DBSegment objects. These are initially defined using a configuration snippet before the library is loaded, using the __db.conditions __db.segments arrays as shown in the sample above.

Defining Conditions

Conditions are evaluations of Demandbase Company Profile attributes, which are represented as a JSON object. Note, at runtime, the JSON objects are converted into DBCondition objects.

A condition has a name, a single attribute (a Demandbase Company Profile field), an operator, and a value (or array of values).

Here is an example of a JSON representation of a condition:

  name : 'condition_name',
  attribute : 'demandbase_variable',
  operator : '=|equals|!=|not equals|contains',
  value : 'attribute value',
  standalone : true|false //optional

The value attribute can be a single value as a string, or an array of string values. If an array is defined, the evaluate function of the DBCondition will return an 'or' operation of the values in the list, because any given attribute from the API response will only have one value for a given visitor.

Supported OperatorSupported Shorthand
equals =
not equals !=
contains contain

Note: These are programmatically accessible using DBCondition.prototype.supportedOperators.

Use the Demandbase.Segments.add function to dynamically create a new Condition:

Demandbase.Segments.add('condition', { name:'MyAudience', attribute: 'audience', operator: 'equals', value: ['SOHO', 'SMB', 'Residential'], standalone: true });

If the standalone attribute is true or omitted from the Condition definition, each Condition will also be added as a Segment. A Segment is Boolean property of the Demandbase.Segments class. These are the properties used to drive content.

Continuing the previous example, this Condition is now available as a Segment (a Boolean property) using Demandbase.Segments.MyAudience, which will return true or false, base on the site visitor's company profile.

Set the standalone attribute to false, if you do not want a Condition to also be added as it's own segment. You can still programmatically check the value of the Condition, but it will not be added as a property of the class.

Defining Segments

Once you've defined Conditions against particular attributes, then you can combine them to build Segments.

If each of your conditions is standalone, then you do not need to define Segments separately. For example, if you want to whether a visitor belongs to one of 5 industries, you can define a standalone Condition for each industry, or you can define a single Condition with an array of industries.

Segments are represented as JSON objects consisting of a name, an operator and an list of Conditions (rules). name is a user-defined value that is used when leveraging the Segment. rules is an array containing names of Conditions operator a Boolean operators (or, and), which is applied to the group of Conditions. These effectively provide 'any' or 'all' operations, so these are supported as well.

Here is an example of a JSON representation of a condition:

  name : 'segment_name',
  rules : ['ConditionName1', 'ConditionName2', 'ConditionNameN'],
  operator : 'any/or/all/and',

Supported operators are any (effectively or) and all (effectively and). This is programmatically available using DBSegment.prototype.supportedOperators.

Supported OperatorEquivalent Shorthand
any or, ||
all and, &&

Build Complex Segments using Multiple Conditions

For Segments that use a single Condition, there is no need to use the __db.segments array or the add function to create a Segment. The Segment will be created when the Condition is added, provided the standalone attribute was not set to false.

For Segments that use multiple Conditions, it is necessary to define them in the __segments array as shown in the implementation sample above.

The rules array in a Segment object is comprised of the name attributes from the defined Condition objects.

In addition to initializing using the __db.segments array, you can also use the Demandbase.Segments.add function to dynamically create a new Segment:

Demandbase.Segments.add('segment', { name: 'UserDefinedName', rules: ['condition_name', 'another_condition_name'], operator: 'any|or|and|all'});

Demandbase.Segments Class

In the implementation snippet above the initialization options in the __db object get assigned to various properties within the library.


Returns true or false for a user-defined Segment as evaluated against the current Demandbase.Segments.CompanyProfile.


A JSON object, this is the visitor profile used to evaluate all segments.

Demandbase.Segments.add(type, newObject)

Used to create a new Condition or Segment. type parameter is either "condition" or "segment". newObject parameter is the JSON definition of either a Condition or a Segment.

Demandbase.Segments.get(type, itemName)

Retrieves a Condition or Segment object. If type parameter is not specified, segment is presumed by default as this is the most common use.


Returns an array of all segments that apply to the current visitor profile.


Returns an array of all segments that are defined but do not apply to the current visitor profile.


Within the Demandbase.Segments class the _allConditions array stores condition objects available for use in segments.

_allConditions: [
    { name: 'IndustryIsSoftware', attribute : 'industry', operator : '=', value : 'Software & Technology', standalone : false },
    { name: 'AudienceIsSMB', attribute : 'audience', operator : 'equals', value : 'SMB' },
    { name: 'AudienceIsEnterprise', attribute : 'audience', operator : 'equals', value : 'Enterprise' },

In this example, "AudienceIsSMB" and "AudienceIsEnterprise" will both also be available as Segments, however, "IndustryIsSoftware" will not, because the standalone flag is set to false.


Similar to Conditions, the _allSegments array stores the currently-defined segments. These intermediate JSON representations are replaced by DBSegment objects at runtime.

_allSegments: [
    { name: 'DemandbaseSegment', rules: ['IndustryIsSoftware', 'AudienceIsSMB'], operator: 'any' },
    { name: 'EnterpriseSegment', rules: ['AudienceIsEnterprise', MyAudience'], operator: 'all' },
Was this article helpful?
0 out of 0 found this helpful