Get Piwik Pro Audiences for segment data in Kameleoon

Written by Julie Trenque

Updated on 03/12/2024

2 min


Manage your integrations






Data Warehouses


Was this content useful?

The available segments in your DMP are being made available by Piwik Pro Audiences via a REST-API.

On your Kameleoon account, click on Administrate in the left-hand menu, then on Projects.

Global custom script

On the card for your site or mobile app, click on Configuration: you’ll now access the configuration of your project on Kameleoon.

Unfold the General section.

The Global custom script insert will enable you to link Kameleoon to Matomo. Any JavaScript code you add in this insert will be executed every time the page is loaded. This feature is usually used to add complex tracking code or integration to other solutions.

Please copy and paste the code below into the Global script section.

const getPiwikProSegments = (visitorID) => {
        const clientID = 'Replace this with your client_id from generated credentials';
        const websiteID = 'Replace this with your project_id';
        const xhr = new XMLHttpRequest();
        xhr.onload = function run() {
            if (this.status === 200) {
                    'Piwik Pro segments',
        };'GET', `${visitorID}?id=${clientID}&website_id=${websiteID}`, true);

    Kameleoon.API.Core.runWhenConditionTrue(() => typeof _paq !== 'undefined', () => {
        _paq.push([function init() {

Click on Validate to apply the changes to your configuration.

Custom data

You then need to create a new custom data.

You will need:

  • your client_id & client_secret for generating Bearer Token (get Credentials);
  • your website_id.

Use the Activation API Method acquisition method. This code should be placed in the Save the values for the targeting condition associated with the custom data point section of the custom data (don’t forget to add your client_id and website_id).

  let segmentPW = [];
     const clientID = 'Replace this with your client_id from generated credentials';
     const websiteID = 'Replace this with you website_id';

     const xhr = new XMLHttpRequest();
     xhr.onreadystatechange = function check() {
         if (this.readyState === 4) segmentPW = JSON.parse(xhr.response);
     };'GET', `${clientID}&website_id=${websiteID}`, false);
     return segmentPW; 

You will notice that in this code we call a Kameleoon Webservice which wraps the Piwik Pro API to get all the segments. This is needed to go throughout CORS policy issues.

The custom data should be set to the list of and strings types, the scope is Page.

External Segment Sync for Server-side

If you would like to use Matomo segment data with one of our SDKs, you will need to follow the guidelines provided in each SDK documentation and use the method retrievedatafromremotesource.

  • In this article :