# Updating page url in datalayer

**URL:** <https://community.piwik.pro/t/updating-page-url-in-datalayer/703>\
**Category:** Data collection and tags\
**Created:** [June 7, 2022, 10:00am UTC](https://community.piwik.pro/t/updating-page-url-in-datalayer/703 "2022-06-07T10:00:38Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mukesh\_Rawat](https://dub1.discourse-cdn.com/flex005/user_avatar/community.piwik.pro/mukesh_rawat/32/448_2.png) [@Mukesh\_Rawat](https://community.piwik.pro/u/Mukesh_Rawat)\
**Post date:** [June 7, 2022, 10:00am UTC](https://community.piwik.pro/t/updating-page-url-in-datalayer/703/1 "2022-06-07T10:00:38Z")

</div>

Hi,

is there any way while pushing dataLayer i can enter the page url as well for page view event like below.

window.dataLayer.push({  
‘url’: `/my/custom/url`,  
‘event’: ‘stg.pageView’  
});  
i want to change page URL to custom, so that while watching goal user flow i can have flow according to URL i am sending

Thanks

---

<div class="post-metadata">

**Author:** ![kuba](https://dub1.discourse-cdn.com/flex005/user_avatar/community.piwik.pro/kuba/32/7_2.png) [@kuba](https://community.piwik.pro/u/kuba)\
**Post date:** [June 7, 2022, 11:04am UTC](https://community.piwik.pro/t/updating-page-url-in-datalayer/703/2 "2022-06-07T11:04:49Z")

</div>

I guess you need just a virtual page view tag 🙂

 ![image](https://europe1.discourse-cdn.com/flex005/uploads/piwikpro/original/1X/f2ad973cab742b8635579b66b8b80826f7ef674b.png)

In this tag, you will be able to use variable from the dataLayer.

Just make sure that:

- the new variable is actually pushed
- you have variable created in the Tag Manager ui that will simply read that value
- I’d also consider using dedicated event name to not change the default behaviour of `stg.pageView` event.

---

<div class="post-metadata">

**Author:** ![Mukesh\_Rawat](https://dub1.discourse-cdn.com/flex005/user_avatar/community.piwik.pro/mukesh_rawat/32/448_2.png) [@Mukesh\_Rawat](https://community.piwik.pro/u/Mukesh_Rawat)\
**Post date:** [June 7, 2022, 11:09am UTC](https://community.piwik.pro/t/updating-page-url-in-datalayer/703/3 "2022-06-07T11:09:24Z")

</div>

> [@kuba](#):
>
> `g.pageView`

Yes but i want to have this url thing with default page view, i want it to consider it as a page view for virtual URL., Thanks i will try and update if it works

---

<div class="post-metadata">

**Author:** ![Mukesh\_Rawat](https://dub1.discourse-cdn.com/flex005/user_avatar/community.piwik.pro/mukesh_rawat/32/448_2.png) [@Mukesh\_Rawat](https://community.piwik.pro/u/Mukesh_Rawat)\
**Post date:** [June 7, 2022, 11:20am UTC](https://community.piwik.pro/t/updating-page-url-in-datalayer/703/4 "2022-06-07T11:20:44Z")

</div>

Hi @kuba ,

What will be the value i should used for below

 ![image](https://europe1.discourse-cdn.com/flex005/uploads/piwikpro/original/1X/d0cecf74583f022f692bb8c26a28d9dd69cbfba8.png)

What will be the value of virtual page and Document title.

Thanks

---

<div class="post-metadata">

**Author:** ![kuba](https://dub1.discourse-cdn.com/flex005/user_avatar/community.piwik.pro/kuba/32/7_2.png) [@kuba](https://community.piwik.pro/u/kuba)\
**Post date:** [June 7, 2022, 11:24am UTC](https://community.piwik.pro/t/updating-page-url-in-datalayer/703/5 "2022-06-07T11:24:05Z")

</div>

OK, so maybe one step back. How are you building the URL? Maybe it’ll be simply enough to override the URL before each page view using this method:

```auto
_paq.push(["setCustomUrl", "https://example.com/virtual-page"]);

```

You just add a new custom html tag on each page view and it should affect all the tracked URLs.

---

<div class="post-metadata">

**Author:** ![Mukesh\_Rawat](https://dub1.discourse-cdn.com/flex005/user_avatar/community.piwik.pro/mukesh_rawat/32/448_2.png) [@Mukesh\_Rawat](https://community.piwik.pro/u/Mukesh_Rawat)\
**Post date:** [June 7, 2022, 11:37am UTC](https://community.piwik.pro/t/updating-page-url-in-datalayer/703/6 "2022-06-07T11:37:28Z")

</div>

Hi ,  
in google analytics i am using it like below

window.dataLayer.push({  
‘page’: `/my/custom/url` ,  
‘event’: ‘gaPageView’  
})

in Piwik you are suggesting like below ?

window.dataLayer.push({  
‘setCustomUrl’: `/my/custom/url` ,  
‘event’: ‘stg.pageView’  
})

Let me brief you with the scenario i am working on, we have registration form popup which has like 12 fields , so for each field i am triggering a pageview event and i want to send custom url as well like for **firstname** it should be **/registeration/desktop/firstname** and so on for all other fields after successful completion of for i will send url as **/registeration/desktop/success** and this same url i will use inside Goals when i will create goal i will add page url contains **/registeration/desktop/success** this way i will have user flow for all fields and i can find out how much numbers are getting drooped from which fields .

I hope i explained it well.

Thanks

---

<div class="post-metadata">

**Author:** ![kuba](https://dub1.discourse-cdn.com/flex005/user_avatar/community.piwik.pro/kuba/32/7_2.png) [@kuba](https://community.piwik.pro/u/kuba)\
**Post date:** [June 7, 2022, 12:18pm UTC](https://community.piwik.pro/t/updating-page-url-in-datalayer/703/7 "2022-06-07T12:18:15Z")

</div>

Let’s try so then:

```auto
window.dataLayer.push({
‘Page Url’: `/my/custom/url` ,
‘event’: ‘stg.pageView’
})

```

---

<div class="post-metadata">

**Author:** ![Mukesh\_Rawat](https://dub1.discourse-cdn.com/flex005/user_avatar/community.piwik.pro/mukesh_rawat/32/448_2.png) [@Mukesh\_Rawat](https://community.piwik.pro/u/Mukesh_Rawat)\
**Post date:** [June 7, 2022, 12:22pm UTC](https://community.piwik.pro/t/updating-page-url-in-datalayer/703/8 "2022-06-07T12:22:15Z")

</div>

Hi @kuba ,

Tried this one but no luck. it still picks browser URL

Thanks

---

<div class="post-metadata">

**Author:** ![kuba](https://dub1.discourse-cdn.com/flex005/user_avatar/community.piwik.pro/kuba/32/7_2.png) [@kuba](https://community.piwik.pro/u/kuba)\
**Post date:** [June 7, 2022, 12:35pm UTC](https://community.piwik.pro/t/updating-page-url-in-datalayer/703/9 "2022-06-07T12:35:21Z")

</div>

Ok, so let’s go with a nice and clean example.

```auto
window.dataLayer.push({
‘CustomUrl’: `/my/custom/url` ,
‘event’: ‘customPageView’
})

```

After sending this event, make sure that you intercept it correctly in the tag manager by:

- adding a variable that will read the CustomUrl
- adding a new virtual page view tag with trigger set to the data layer event called `customPageView`

Of course, please make sure you use the newly created variable as the page url for your new virtual page view 🙂 For the title of the page, you can use another JavaScript variable that will be set to `document.title`.

---

<div class="post-metadata">

**Author:** ![Mukesh\_Rawat](https://dub1.discourse-cdn.com/flex005/user_avatar/community.piwik.pro/mukesh_rawat/32/448_2.png) [@Mukesh\_Rawat](https://community.piwik.pro/u/Mukesh_Rawat)\
**Post date:** [June 7, 2022, 12:46pm UTC](https://community.piwik.pro/t/updating-page-url-in-datalayer/703/10 "2022-06-07T12:46:59Z")

</div>

This how it looks now

 ![image](https://europe1.discourse-cdn.com/flex005/uploads/piwikpro/original/1X/da1525becea27bfd80517b4d16877487c28c692b.png)

 ![image](https://europe1.discourse-cdn.com/flex005/uploads/piwikpro/original/1X/883bdf5476b30bfb5f64f4cf490302fc5f464926.png)

---

<div class="post-metadata">

**Author:** ![kuba](https://dub1.discourse-cdn.com/flex005/user_avatar/community.piwik.pro/kuba/32/7_2.png) [@kuba](https://community.piwik.pro/u/kuba)\
**Post date:** [June 7, 2022, 12:50pm UTC](https://community.piwik.pro/t/updating-page-url-in-datalayer/703/11 "2022-06-07T12:50:38Z")

</div>

I guess for the document.title you have to create a new `Document` variable because otherwise it will simply display it as text.

 ![image](https://europe1.discourse-cdn.com/flex005/uploads/piwikpro/original/1X/e7d002cf24ce993154395d81a0e0eb619edb66e0.png)

Does it work? You can always check it using the Tag Manager debugger and the Tracker debugger functionalities.

---

<div class="post-metadata">

**Author:** ![Mukesh\_Rawat](https://dub1.discourse-cdn.com/flex005/user_avatar/community.piwik.pro/mukesh_rawat/32/448_2.png) [@Mukesh\_Rawat](https://community.piwik.pro/u/Mukesh_Rawat)\
**Post date:** [June 7, 2022, 1:31pm UTC](https://community.piwik.pro/t/updating-page-url-in-datalayer/703/12 "2022-06-07T13:31:39Z")

</div>

Not sure if everything ok, as now nothing getting tracked

 ![image](https://europe1.discourse-cdn.com/flex005/uploads/piwikpro/original/1X/94ceb8ca046542aca514a6ee43d5d9b57d284076.png)

 ![image](https://europe1.discourse-cdn.com/flex005/uploads/piwikpro/original/1X/5bcebd64f0e4fb994617b1cd05eb287ad343d154.png)

 ![image](https://europe1.discourse-cdn.com/flex005/uploads/piwikpro/original/1X/d61ad857a3fbbd7fae0985d3c1eb606faaed5ccd.png)

 ![image](https://europe1.discourse-cdn.com/flex005/uploads/piwikpro/original/1X/40b9d4979affa1166ecdc79940c01f25ba524ac4.png)

Please have a look on screenshot i shared

Thanks

---

<div class="post-metadata">

**Author:** ![kuba](https://dub1.discourse-cdn.com/flex005/user_avatar/community.piwik.pro/kuba/32/7_2.png) [@kuba](https://community.piwik.pro/u/kuba)\
**Post date:** [June 7, 2022, 1:35pm UTC](https://community.piwik.pro/t/updating-page-url-in-datalayer/703/13 "2022-06-07T13:35:12Z")

</div>

In the trigger, the event name constraint should be set to CustomPageView. I noticed that the consent type is set to Analytics. Are you using the consent manager? Does the tag fire in the [debug mode](https://help.piwik.pro/support/tag-manager/debug-mode/)?

---

<div class="post-metadata">

**Author:** ![Mukesh\_Rawat](https://dub1.discourse-cdn.com/flex005/user_avatar/community.piwik.pro/mukesh_rawat/32/448_2.png) [@Mukesh\_Rawat](https://community.piwik.pro/u/Mukesh_Rawat)\
**Post date:** [June 8, 2022, 7:01am UTC](https://community.piwik.pro/t/updating-page-url-in-datalayer/703/14 "2022-06-08T07:01:26Z")

</div>

> [@kuba](#):
>
> CustomPageView

Thanks it worked now 🙂

---

<div class="post-metadata">

**Author:** ![rmeekers](https://dub1.discourse-cdn.com/flex005/user_avatar/community.piwik.pro/rmeekers/32/929_2.png) [@rmeekers](https://community.piwik.pro/u/rmeekers)\
**Post date:** [November 25, 2022, 2:30pm UTC](https://community.piwik.pro/t/updating-page-url-in-datalayer/703/15 "2022-11-25T14:30:55Z")

</div>

@kuba  
I’m trying to set a custom URL through a custom code tag that loads before the _Piwik Pro basic tracking code_.

```auto
<script>
  _paq.push(['setCustomUrl', {{ PageURL clean }}]);
</script>

```

But I get this error in my console:

`Uncaught ReferenceError: _paq is not defined`

I don’t understand why. Isn’t `_paq` initialised when the tag manager loads? Or is the initialisation only done when the main _Piwik Pro basic tracking code_ is fired? And if this is the case, how can I override the page URL using the command queue?

---

<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 25, 2022, 3:09pm UTC](https://community.piwik.pro/t/updating-page-url-in-datalayer/703/16 "2022-11-25T15:09:49Z")

</div>

Hi @rmeekers  
All of our tags in Piwik PRO Tag Manager start with the following part:

`var _paq = _paq || [];`

This way you know for sure the array (or queue) is available to have commends like yours pushed through.

By default this is created when setting up the actual tracker.

Cheers,  
Richard

---

<div class="post-metadata">

**Author:** ![rmeekers](https://dub1.discourse-cdn.com/flex005/user_avatar/community.piwik.pro/rmeekers/32/929_2.png) [@rmeekers](https://community.piwik.pro/u/rmeekers)\
**Post date:** [November 25, 2022, 3:18pm UTC](https://community.piwik.pro/t/updating-page-url-in-datalayer/703/17 "2022-11-25T15:18:49Z")

</div>

Wonderful. I didn’t know that it could work like this.  
🙏

---

<div class="post-metadata">

**Author:** ![kuba](https://dub1.discourse-cdn.com/flex005/user_avatar/community.piwik.pro/kuba/32/7_2.png) [@kuba](https://community.piwik.pro/u/kuba)\
**Post date:** [November 25, 2022, 3:44pm UTC](https://community.piwik.pro/t/updating-page-url-in-datalayer/703/18 "2022-11-25T15:44:46Z")

</div>

The thing is that all the code is used asynchronously, once the ppms.js library is loaded. So, you can even configure parts of the Analytics tracking code before loading the Piwik PRO tag. 🙂
