How to Target Campaigns to URLs with Query Arguments

OptinMonster makes it easy to show or hide campaigns to visitors on your site based on the query arguments in the URL.

In this article, you’ll learn how to target campaigns to URLs with query arguments.

Before You Start

Here are some things to know before you begin:

  • Query argument targeting requires a Pro or higher subscription.
  • Query arguments contain a key and a value, and come after a question mark in the URL like this: http://domain.com/?key=value
  • A URL can contain multiple sets of query arguments, separated by an ampersand like this: http://domain.com/?key=value&key2=value2&key3=value3
  • The term “query argument” is also sometimes called “query string”.
  • This article covers specific settings in the Display Rules. If you’re just getting started we recommend reading our general Display Rule documentation first.

Query Argument Targeting

Query argument targeting requires a Pro or higher subscription.

When you create a campaign in OptinMonster you can target only URLs on your site that contain certain query arguments.

To show or hide your campaign on URLs with query arguments, follow these steps:

  1. In the campaign builder, navigate to the Display Rules view.
    show display rules
  2. Begin editing your rules and when adding a new rule choose the URL query arg option from the dropdown.
    Query Arg Rule
  3. Next, you’ll have the following match options available for both the key and value:
    • exactly matches
    • does not exactly match
    • contains
    • does not contain
    • starts with
    • does not start with
    • ends with
    • does not end with
    • is anything
    • matches the pattern
  4. Finally, enter the name of the key and value, if you’re doing any type of matching, into the provided fields.
  5. When you’re finished, click Save.

Examples

Here are some examples to help you get started.

E-Commerce

If your e-commerce platform uses query arguments in the URL to add products to the shopping cart you could show a specific campaign when a visitor adds a specific product to their cart.

Let’s assume your e-commerce site uses a query argument structure like the following to add a product to the shopping cart:

http://www.example.com/checkout/?add-to-cart=532

The URL has one query argument key and one query argument value:

Key: add-to-cart
Value: 532

When the above URL is visited on our example e-commerce store, the product with ID 532 is automatically added to the visitor’s shopping cart.

Now, we can target a campaign to show only when a URL with that query argument is visited. Perhaps we want to offer a specific upsell in the campaign when the product with ID 532 is added to the cart.

To do this, we’ll add a query arg rule to the Display Rules and enter the key and value with exactly matches condition.

Ecommerce Query Arg

Site Search

Some websites will use query arguments in the URL to generate search results. If your website follows this convention you can use query argument targeting to show a specific campaign to visitors who search for a certain term.

For most websites, the query string for searches will look similar to the following:

https://optinmonster.com/?s=content+upgrades

For the URL above, there is one query argument key and one query argument value.

Key: s
Value: content+upgrades

*The plus (+) sign typically represents a space between search terms since a URL cannot contain spaces.

Now, we can target a campaign to show only when a URL with that query argument is visited. This may be a good opportunity to show a campaign that offers a free ebook related to content upgrades.

To do this, we’ll add a query arg rule to the Display Rules and enter the key and value with exactly matches condition.

Search Query Arg

 

Troubleshooting

How do I show the campaign when a query argument value does not match?

Since the query argument key condition is required, this will require two rules to be added in a single ruleset in the Display Rules.

In this example, we’ll set a campaign to show if the query argument’s value does not match some_medium.

Here is the URL we’re targeting:

http://example.com/?utm_medium=some_medium

The first rule would have the following settings:

Show when “query argument key does not match ‘utm_medium’ and query argument value ‘is anything'”.

Not Match Key Target

This will show to all users who do not have that key at all.

Next, add another OR rule to the ruleset and we would configure the second rule as follows:

Show when “query argument key exactly matches ‘utm_medium’ and query argument value does not match ‘some_medium'”

Not Match Value Target

This will show to users who have the key, but with a different value.