Change page url in case of no page view tag : The solution!

Hi all,

I am using MTM 4.0.1 on an old website that use frames. :roll_eyes:

The left frame is just a menu frame and the right frame is the main frame.
Because the URLs are managed by a kind of CMS, all URL of the site are the same, so I need to ask Matomo to translate page URL: pagebuilder.aspx?some=parameters => /root/branch/leave

As I don’t want to pollute the tracking by page-hits on the menu (as functionally it is not a new page, but a “part” of the page) I did the following:

  1. Create a datalayer variable to store the translated urlpage: {{pageUrl}}
  2. Create some custom tags based on custom events.
  3. Create a pageView event that will be fired by the main-frame page-view only
  4. Add the page view tag on the pageView event and use {{pageUrl}} as URL parameter:

This work fine for the main frame. It tracks all page views all and custom events with my custom URL. :+1:

For now, the menu frame do not track page view. OK. In order to configure the link tracking on the menu, I added an event linkEventMenu of type All links clicks and its associated tag:

Now I track the links clicks, but the page URL is not configured. This is what I tried:
First, I created a pageNoView event that will be fired by the menu-frame page-view only.

Then I tried to use the following HTML-tag based on the pageNoView event:

<script type="text/javascript">
  var _paq = window._paq = window._paq || [];
  _paq.push(['setCustomUrl', {{pageUrl}}]);
  _paq.push(['setDocumentTitle', {{pageName}}]);

But this updates the custom URL only after the 1st link click: the 1 click is tracked on the real URL and the 2nd on the translated one.

Finally I added a last tag, also on the pageNoView event of type Initialise tracker only. Don' track anything.

This solved my problem.

Maybe this use case could be added to the FAQ?