Is pkBaseURL required?

hi,

I have a site that is accessed both by internal and external users on different ports and different domains. The problem is the pkBaseURL when it is created is only reachable by one or the other.

Is there a way to make the script be relative to the domain its being called from instead of an absolute URL?

Thanks

There’s no way for the Piwik UI to know about your internal/external setup though, but you can change pkBaseUrl – in fact, any part of the tracking code – to suit your needs.

I understand that, but for my tracking code it puts in a hard coded domain/IP, can the code not be set to not use that?

is there no way to have ‘external-domain.com’ replaced with something that would insert the hostname that the script is being called from? Or even excluded completely and just the /piwik/ paths used and appended to the current domain?

This would address the issue as users would then be able to hit piwik regardless as it would have the correct domain…

does this make sense?

How should the script know where it can find the piwik.js? if you are on the same domain you can replace ‘external-domain.com’ with ‘window.location.hostname’

so do you mean I could do this:


<!-- Piwik -->
<script type="text/javascript">
var pkBaseURL = (("https:" == document.location.protocol) ? "https://'window.location.hostname'/piwik/" : "http://'window.location.hostname'/piwik/");
document.write(unescape("%3Cscript src='" + pkBaseURL + "piwik.js' type='text/javascript'%3E%3C/script%3E"));
</script><script type="text/javascript">
try {
var piwikTracker = Piwik.getTracker(pkBaseURL + "piwik.php", 1);
piwikTracker.trackPageView();
piwikTracker.enableLinkTracking();
} catch( err ) {}
</script><noscript><p><img src="http://'window.location.hostname'/piwik/piwik.php?idsite=1" style="border:0" alt="" /></p></noscript>
<!-- End Piwik Tag -->

if so that could work…

don’t forget the ‘+’ when connecting strings:

“https://”+window.location.hostname+"/piwik/"

great thanks, this does exactly what i want it to now.