Allow Matomo Configuration Matomo idSite field to use a Variable


(Scott Fillman) #1

When I try to dynamically add the Matomo idSite field in the Matomo Configuration Variable, based on a data layer variable read in a custom JS variable, I receive an error:

It would be great to be able to set different site IDs for each environment dynamically by using a case statement (or lookup table) to lookup which environment is populated in the data layer and allow the variable value to be used as the site ID.

For example to be able to create a Custom JavaScript variable like this:

function () {
    var _mtmId;
    switch(dataLayer[0].app.systemEnvironment) {
    case "ci":
        _mtmId = "2";
        break;
    case "si":
        _mtmId = "2";
        break;
    case "uat":
        _mtmId = "2";
        break;
    case "staging":
        _mtmId = "2";
        break;
    case "prod":
        _mtmId = "1";
        break;
    default:
        _mtmId = "2";
    }
    return _mtmId;
}

To assign the Matomo idSite field in the Matomo Configuration Variable. If this functionality already exists and I am just approaching it the wrong way, please let me know,


(Lukas Winkler) #2

Hi,

If I understand you correctly, you should be able to do exactly what you want by using lookup tables:

https://matomo.org/docs/tag-manager/#advanced-variables-settings-default-value-lookup-table


(Scott Fillman) #3

Hi Lukas. Thank you for sharing the link for creating lookup tables. This is incredibly helpful and I now see how to set that up. For some reason, I am still getting an error message when I try to save the Matomo Configuration variable using the lookup table variable:

I will continue to troubleshoot - I am new to Matomo so likely may need to dig in a bit more.

Thanks again!