How to set up a custom HTML targeting condition

Keep in mind

Please note that this is an advanced feature that requires some programming knowledge. Therefore, we are unable to provide support for creating or troubleshooting custom code.

You can use a custom HTML condition to show (or hide) widgets based on the presence of a given HTML element on a specific page of the website.

For example, you can use this feature to display (or not display) a widget when there is at least one item in the cart.

Identify the HTML element

On your website, there likely is a unique HTML element that indicates the number of items the customer added to the cart.

The examples below show how the same element changes as items are added to the cart.

Empty cart

<div class="cart-item-count">0</div>

One item in the cart

<div class="cart-item-count">1</div>

Two items in the cart

<div class="cart-item-count">2</div>

With an HTML condition, you can identify the element using the CSS selector, and show the widget if this element’s value (innerText) is higher than 0.

Add the CSS selector

When setting up targeting for your widget, find the ‘Display widget if’ section. Switch to the ‘Developer’ tab and click HTML condition.

The HTML condition in the widget targeting settings

Then, add the HTML element’s CSS selector to the corresponding field.

For our example, we’ll use a class selector. Make sure to add a dot (.) before the class name.

CSS selector for the cart count

.cart-item-count
Adding the HTML element’s class to the CSS selector field

Feel free to use any of the other CSS selectors for different scenarios.

Choose a condition

Next, choose an option from the dropdown list:

Choosing an option from the dropdown list

Choose the condition that fits the text or number returned by your CSS selector:

ConditionWhat it checks
IsThe value equals the value you enter. For example, a cart count of 0.
Is notThe value differs from the value you enter.
Less thanThe number is below your threshold. For example, a cart count below 3.
Greater thanThe number is above your threshold. A cart count greater than 0 means there is at least one item.
Starts withThe text begins with the text you enter. For example, “Order” matches “Order confirmed”.
Ends withThe text ends with the text you enter. For example, “remaining” matches “2 remaining”.
ContainsThe text includes the text you enter anywhere within it. For example, “stock” matches “Back in stock”.
Does not containThe text does not include the text you enter.
MatchesThe text fits a pattern. Use * for any sequence of characters: “Order * confirmed” matches “Order 123 confirmed”.
Does not matchThe text does not fit the pattern you enter.
Has any valueThe selector finds an element on the page. You do not need to enter a comparison value.
Is unknownThe selector does not return a value, for example because no matching element is found.

Set the comparison value

Since we want to show a popup when there is at least one item in the cart, we’ll have to pick greater than and then add “0” to the second field:

The HTML condition setup

And that’s it!

Getsitecontrol will look for the HTML element based on the CSS selector specified in the targeting rule. Then, if the value of that element matches the targeting settings, the popup will appear on the webpage.

The HTML condition allows you to set up a variety of scenarios. Feel free to experiment with different HTML conditions to create precise targeting settings for your purposes.