URL Redirect in Javascript


#1

I have moved the current Piwik installation from the service provider to our own server, but with different DNS name of the site. Because the Javascript has been inserted to every pages of a large number of sites and pages, I need to keep the old domain name. I did a website redirect (HTTP), but the URL in the Javascript with query string appended with idsite=“xxx” does not work with this HTTP site redirect,. What is the solution to this problem, except updating the Javascript (it may requires lots of work, as we have nearly 100 sites with many, many pages, many sites may not configured using SSI, so updating Javascript is only the last option…)?

I need help.

Thanks

Bob:)


(Matthieu Aubry) #2

Bob

take a look at; Document how to hide piwik server URL in the Javascript · Issue #2019 · matomo-org/matomo · GitHub

you will find there a script that does this redirect, as it is more complex than what you tried :wink:


#3

Hi Matt,

Thanks so much. It does seem more complicated than what I thought originally. I will go through this and may be run some tests to see if which way works the best. It looks like the php “proxy” is the best one.

Much appreciated.

Bob


(Matthieu Aubry) #4

the proper solution is seen in the comments in the ticket itself, not the description


#5

Thanks for reminding me of that, I need to be more patient to read the whole thread. Bob


#6

Having read through the ticket and comments, my impression was it still needs to update the javascript on each page of the site, and update or replace the piwik.php to each site Piwik tracks.

Looking into the javascript itself, the only site specific part is the pkBaseURL, which is my problem because the Piwik installation came from the other server. The current Piwik has a differnt domain name.

I do not understand the whole idea of the solution, and not sure if it can solve my problem. As I said, I already configured a redirect from the old site name to the new one, but it seems not working as no stats have been collected (no data).

I may end up with having to update the javascript on each page…

Bob


(Matthieu Aubry) #7

The solution proposed in the ticket does not involve changing the javascript, the proposed ‘piwik.php’ script becomes a proxy to both the JS and the Tracking request…


#8

Just confirm that, I need to put the piwik.php, as attached here, updated with the following:

$PIWIK_URL = ‘http://new domain/’; and

$TOKEN_AUTH = ‘xyz’

, to eery site that Piwik tracks stats, that’s it. But you did mention that “Then modify the top part of the Piwik JS snippet to the following”, which actuallly change the domain name to that of the target site. My understanding is the javascriopt must be updated with the sites’ URL for each site, let me know if I am wrong.

By the way, how to get $TOKEN_AUTH, when login in as super user (account when setup Piwik, also in the config file)? Can I have some instructions, please?

Thanks and much appreciated.


(Matthieu Aubry) #9

Oh sorry I forgot about your initial post, and didn’t see that you couldn’t update the javascript on all sites :frowning:

I’m afraid that for you only the CNAME solution could maybe work? ie. point the CNAME of your old server to the new one?

For token_auth, see the (new) faq: General - Analytics Platform - Matomo


#10

Try this …Javascript Redirect

Lee


#11

Hope this will help you…Javascript Redirect

Walsh