Testing Matomo Implementations within GTM

When debugging Matomo (formerly PiWik) with Google Tag Manager (GTM), you may have noticed that the Matomo scripts execute and send data to your Matomo server. This is because while GTM is designed not to send data for Google Analytics tags, all JavaScript or other code in HTML tags do execute. The Matomo code then fires and sends its data to the servers as it fires within the HTML tag.

(Read our earlier post to learn how to use GTM for Matomo</A> tagging.)

With a Matomo Site ID Constant Variable

  1. Create a Matomo Site ID for development purposes
  2. Create a GTM constant variable for the Matomo Site ID
  3. Use the Matomo Site ID Constant Variable within the Matomo tracking script such as

    _paq.push(['setSiteId', '{{Matomo SiteID}}']);
     
  4. Complete your testing.
  5. When done, change the Matomo Site ID to your production report Site ID and PUBLISH.

Dynamically with a Lookup Table

You can also use a dynamic setting based on the use of the PREVIEW mode. When GTM PREVIEW is in use, activate GTM in its DEBUG mode. You can check if this is active and, if so, use the development Site ID and, if not, use the production Site ID. 

  1. Create a Matomo Site ID for development purposes.
  2. Activate the GTM DEBUG variable.

    Matomo Configure Variables
  3. Create a Look Up table with the input value as the DEBUG variable.
  4. Place two lines in the Lookup Table:  true and false.
  5. For the value of true (DEBUG is on), place in your development Matomo Site ID. This could also be a constant variable if you use this Site ID elsewhere.
  6. For the value of false (DEBUG is on), place in your production Matomo Site ID. This could also be a constant variable if you use this Site ID elsewhere.
  7. We set the Default Value to your production Matomo Site ID. This is not actually necessary, but we have seen UNDEFINED for the debug variable. This is there as a safety point to ensure data is tracked even if the DEBUG MODE variable has an error.

    Matomo Variable Configuration
  8. Use the Matomo Site ID Lookup Table Variable within the Matomo tracking script such as:

    _paq.push(['setSiteId', '{{Matomo Site ID Lookup}}']);
     
  9. You should now test in both Preview and Published mode that the proper Site ID is used. You will now have a method that automictically directs traffic based on the PREVIEW setting for any user.

Let’s talk.

Name