Build an audience of frequent visitors

The necessary tools: 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:
  2. <script>
        (function(a,d,g,h,b,c,e){
          a[b]=a[b]||{};a[b][c]=a[b][c]||{};a[b][c][e]=a[b][c][e]||function(){(a[b][c][e].q=a[b][c][e].q||[]).push(arguments)};
          var f=d.createElement(g);d=d.getElementsByTagName(g)[0];
          f.async=1;
          f.src=h;
          d.parentNode.insertBefore(f,d)
        })
        (window,document,"script","https://clearbank.piwik.pro/audiences/static/widget/audience-manager.api.min.js","ppms","am","api");
    
        ppms.am.api("create", "00000000-0000-0000-0000-000000000000", "clearbank.piwik.pro");
      
          var attributes = {
            "session_count": {
                "action": "add",
            }
        }
          ppms.am.api("updateAttributes", attributes);
    </script>
    
  3. In this URL https://clearbank.piwik.pro/audiences/static/widget/audience-manager.api.min.js change https://clearbank.piwik.pro/ to the name of your account.
  4. In this line of code ppms.am.api("create", "00000000-0000-0000-0000-000000000000", "clearbank.piwik.pro"); change the number 00000000-0000-0000-0000-000000000000 to your website ID and change clearbank.piwik.pro to the name of your account.
  5. 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 + Create new tag.
  3. Name the tag and pick Custom asynchronous tag template.
  4. Click Save.
  5. In the code editor, type the modified code.
  6. Scroll down until you see Tag triggers, and click +Add new trigger.
  7. Name the trigger.
  8. Set the Page view event type.
  9. Set Fire tag once per session. The tag will fire once per session, so we’ll get the correct number of sessions.
  10. Click Save for the trigger and 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 + Create new audience.
  3. Name the audience.
  4. On the right, find the attribute you’ve set in the code. In our example, session number.
  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.
  7. Click Save.

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

Was this article helpful?

Be the first to rate this article.

Technical Support

If you have any questions, drop us a line at support_SPC@piwik_SPC.pro.

We’re happy to help!