How can I set a custom URL for Pageviews?

In some cases, e.g. due to values in the URL path that should not be tracked anywhere because they contain personal data, we need to set a custom URL when we track pageviews.
So we need to clean the URL before we send it to Piwik.
This is no problem with Adobe or Google Analytics. But in Piwik’s case, the only accepted parameter is “customPageTitle”, so I can customize the Page Title, but not the tracked URL:

This needs to be added to PiwikPRO.
Or am I missing something?

Hi @loldenburg ,

you can add _paq.push([“setCustomUrl”, “https://example.com/virtual-page”]);
before calling trackPageView
As documented here:
API — Piwik PRO Analytics Suite 16.33 documentation

1 Like

Thanks! Maybe Piwik can add that hint to the trackPageview method in your documentation, I don’t think this is obvious. I spent half the day searching.

It is usually done by setting up the Virtual Pageview tracking tag in Tag Manager, where you can add the (custom) Page URL and Page Title.

But since you were pointing to the javascript tracking client API, I thought let’s guide you there.

Thanks for asking in the community, after all that’s what it is for.

1 Like

Thanks. I don’t use the Piwik Tag Manager, we have a lot of stuff in GTM already, and I want to hook onto the existing logic there. The Piwik GTM Tag Template does not seem to offer much besides basic pageview tracking and some auto-events, so we need to do it via the JS API. Correct me if that is wrong, I have only spent 3 days with the tool so far.

When you intend to use all features of Piwik PRO, Tag Manager, consent Manager and Analytics, I would definitively use the integration as it is written by the Install manually (Install a container (with a tracking code) | Piwik PRO help center) , because all modules know about each other (especially the consent manager and tag manager in case of GDPR and the like)

Tag Manager and Analytics work well together when using for instance custom dimensions.

Thx. I definitely don’t want a second Tag Manager on the same site.
And I want to limit Custom HTML in GTM as much as possible.
Consent Manager already exists on that site, so I only need Analytics.

Hi! Regarding this solution, I guess the only way to do this would be to run the setCustomUrl in the source code? Any thoughts on whether there might be a feature coming that would allow this in the UI?

Like with customTask in UA and the Config var in GA4, it would be nice to be able to control event_url and referrer_url before they get sent to Piwik.

Not really, you can use a custom HTML tag that fires before the main Piwik PRO tag (How can I override the default Page URL without causing duplicate pageviews in PP TM? - #2 by anthonybartczak) or use the manual page view tracking with the virtual page view tag. Let me know if I’m missing something that might be blocking you from using these methods.

edit: by the way - I’ll file another feature request because it would be nice to be able to modify this directly in the Piwik PRO tag.

1 Like