# How can I set a custom URL for Pageviews?

**URL:** <https://community.piwik.pro/t/how-can-i-set-a-custom-url-for-pageviews/1290>\
**Category:** Data collection and tags\
**Created:** [November 23, 2022, 4:00pm UTC](https://community.piwik.pro/t/how-can-i-set-a-custom-url-for-pageviews/1290 "2022-11-23T16:00:22Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![loldenburg](https://dub1.discourse-cdn.com/flex005/user_avatar/community.piwik.pro/loldenburg/32/965_2.png) [@loldenburg](https://community.piwik.pro/u/loldenburg)\
**Post date:** [November 23, 2022, 4:00pm UTC](https://community.piwik.pro/t/how-can-i-set-a-custom-url-for-pageviews/1290/1 "2022-11-23T16:00:22Z")

</div>

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:

> **[API](https://developers.piwik.pro/en/latest/data_collection/web/javascript_tracking_client/api.html#trackPageView)**
>
> The following API allows the user to: track page views, track visits on multiple domains and subdomains, track e-commerce events (successful orders, cart changes, product and category views), track...

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

---

<div class="post-metadata">

**Author:** ![rmastop](https://dub1.discourse-cdn.com/flex005/user_avatar/community.piwik.pro/rmastop/32/29_2.png) [@rmastop](https://community.piwik.pro/u/rmastop)\
**Post date:** [November 23, 2022, 4:14pm UTC](https://community.piwik.pro/t/how-can-i-set-a-custom-url-for-pageviews/1290/2 "2022-11-23T16:14:43Z")

</div>

Hi @loldenburg ,

you can add \_paq.push([“setCustomUrl”, “[https://example.com/virtual-page](https://example.com/virtual-page)”]);  
before calling trackPageView  
As documented here:  
[API — Piwik PRO Analytics Suite 16.33 documentation](https://developers.piwik.pro/en/latest/data_collection/web/javascript_tracking_client/api.html#setCustomUrl)

---

<div class="post-metadata">

**Author:** ![loldenburg](https://dub1.discourse-cdn.com/flex005/user_avatar/community.piwik.pro/loldenburg/32/965_2.png) [@loldenburg](https://community.piwik.pro/u/loldenburg)\
**Post date:** [November 23, 2022, 4:17pm UTC](https://community.piwik.pro/t/how-can-i-set-a-custom-url-for-pageviews/1290/3 "2022-11-23T16:17:01Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![rmastop](https://dub1.discourse-cdn.com/flex005/user_avatar/community.piwik.pro/rmastop/32/29_2.png) [@rmastop](https://community.piwik.pro/u/rmastop)\
**Post date:** [November 23, 2022, 4:26pm UTC](https://community.piwik.pro/t/how-can-i-set-a-custom-url-for-pageviews/1290/4 "2022-11-23T16:26:46Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![loldenburg](https://dub1.discourse-cdn.com/flex005/user_avatar/community.piwik.pro/loldenburg/32/965_2.png) [@loldenburg](https://community.piwik.pro/u/loldenburg)\
**Post date:** [November 23, 2022, 4:29pm UTC](https://community.piwik.pro/t/how-can-i-set-a-custom-url-for-pageviews/1290/5 "2022-11-23T16:29:10Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![rmastop](https://dub1.discourse-cdn.com/flex005/user_avatar/community.piwik.pro/rmastop/32/29_2.png) [@rmastop](https://community.piwik.pro/u/rmastop)\
**Post date:** [November 23, 2022, 4:44pm UTC](https://community.piwik.pro/t/how-can-i-set-a-custom-url-for-pageviews/1290/6 "2022-11-23T16:44:36Z")

</div>

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](https://help.piwik.pro/support/getting-started/install-a-tracking-code/)) , 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.

---

<div class="post-metadata">

**Author:** ![loldenburg](https://dub1.discourse-cdn.com/flex005/user_avatar/community.piwik.pro/loldenburg/32/965_2.png) [@loldenburg](https://community.piwik.pro/u/loldenburg)\
**Post date:** [November 23, 2022, 7:39pm UTC](https://community.piwik.pro/t/how-can-i-set-a-custom-url-for-pageviews/1290/7 "2022-11-23T19:39:43Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![mikkovai](https://dub1.discourse-cdn.com/flex005/user_avatar/community.piwik.pro/mikkovai/32/1881_2.png) [@mikkovai](https://community.piwik.pro/u/mikkovai)\
**Post date:** [January 16, 2024, 7:54am UTC](https://community.piwik.pro/t/how-can-i-set-a-custom-url-for-pageviews/1290/8 "2024-01-16T07:54:53Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![anthonybartczak](https://dub1.discourse-cdn.com/flex005/user_avatar/community.piwik.pro/anthonybartczak/32/2430_2.png) [@anthonybartczak](https://community.piwik.pro/u/anthonybartczak)\
**Post date:** [January 16, 2024, 9:28am UTC](https://community.piwik.pro/t/how-can-i-set-a-custom-url-for-pageviews/1290/9 "2024-01-16T09:28:48Z")

</div>

> [@mikkovai](#):
>
> Regarding this solution, I guess the only way to do this would be to run the setCustomUrl in the source code?

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](https://community.piwik.pro/t/how-can-i-override-the-default-page-url-without-causing-duplicate-pageviews-in-pp-tm/3407/2)) 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.
