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:
- This is the code you need to modify:
<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>
- In this URL
https://clearbank.piwik.pro/audiences/static/widget/audience-manager.api.min.js
changehttps://clearbank.piwik.pro/
to the name of your account. - In this line of code
ppms.am.api("create", "00000000-0000-0000-0000-000000000000", "clearbank.piwik.pro");
change the number00000000-0000-0000-0000-000000000000
to your website ID and changeclearbank.piwik.pro
to the name of your account. - 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:
- Go to Menu > Tag Manager.
- Click Add a tag.
- Name the tag and select the following type: Custom code (async) (custom asynchronous tag).
- Click Next.
- In Tag code, type the modified code.
- In Tag triggers, click Add a trigger.
- Name the trigger and set the following type: Page view.
- In Multiplicity, set Fire tag once per session. The tag will fire once per session, so we’ll get the correct number of sessions.
- Click OK.
- Click Save for the tag.
- 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:
- Go to Menu > Audience Manager.
- On the left, click Add new audience.
- Name the audience.
- On the right, find the attribute you’ve set in the code. In our example,
session number
.
- Drag and drop the attribute to the left-hand drop point.
- Set conditions for this attribute, for example,
Session number is greater than 5
.
- Click Save.
Now your audience is ready and you can use it to:
- Fire tags for the audience.
- Export an Audience to a CSV File
- Export an Audience to Google Ads
- Export an Audience to Facebook