How to build an audience of people who visit your site often

Audience Manager + Tag Manager

If you want to build an audience of people who visited your website several times to target them with your marketing campaigns, you need to do a custom setup. At the moment, in Audience Manager, you won’t find the attribute with the number of sessions. Therefore you’ll need to use a custom code that will count the number of sessions and pass this information as an attribute to Audience Manager. 

In this article, we’ll show you how to prepare the code, install it to your website using the tag and trigger, and finally build an audience.

Before you start

Here are some things to know before you start the whole setup:

  • The audience built with this method will include visitors with sessions counted after installing this code on your website. It will not work for data in the past.

Prepare the code

First, you need to modify the following code so that it refers to your website.

To get the code ready, follow these steps:

  1. This is the code you need to modify:
          var f=d.createElement(g);d=d.getElementsByTagName(g)[0];
   "create", "00000000-0000-0000-0000-000000000000", "");
          var attributes = {
            "session_count": {
                "action": "add",
"updateAttributes", attributes);
  2. In this URL change to the name of your account.
  3. In this line of code"create", "00000000-0000-0000-0000-000000000000", ""); change the number 00000000-0000-0000-0000-000000000000 to your website ID and change to the name of your account.
  4. Optionally, you can change session_count to a different name. This is the name of an attribute that will appear in Audience Manager.

This code connects to Piwik PRO API, counts the number of sessions for a visitor, and sends this information to Audience Manager.

Install the code using a tag and trigger

Once you have the code ready, you need to create a tag in Tag Manager that will install this code on your website and a trigger that will make this code run every time a person visits your website.

To install the code, follow these steps:

  1. Go to Menu > Tag Manager.
  2. Click Add a tag.
  3. Name the tag and select the following type: Custom code (async) (custom asynchronous tag).
  4. Click Next.
  5. In Tag code, type the modified code.
    Tag Manager in Piwik PRO
  6. In Tag triggers, click Add a trigger.
  7. Name the trigger and set the following type: Page view.
  8. In Multiplicity, set Fire tag once per session. The tag will fire once per session, so we’ll get the correct number of sessions.
    Multiplicity in Piwik PRO
  9. Click OK.
  10. Click Save for the tag.
  11. Click Publish to make the tag go life.

Build an audience

Once the tag with the trigger is published you need to wait about 15 minutes so that Audience Manager updates the list of attributes. After that time, you can continue setting up the audience.

To build an audience of frequent visitors, follow these steps:

  1. Go to Menu > Audience Manager.
  2. On the left, click Add new audience.
  3. Name the audience.
  4. On the right, find the attribute you’ve set in the code. In our example, session number.
    Audience Manager in Piwik PRO
  5. Drag and drop the attribute to the left-hand drop point.
  6. Set conditions for this attribute, for example, Session number is greater than 5.
    Audience Manager in Piwik PRO
  7. Click Save.

Now your audience is ready and you can use it to:

Was this article helpful?

Technical support

If you still have some questions, visit our community.
There’s always someone ready to help!

Related articles

Back to help center