Seperating multiple subdomains


#1

Hi,

I’m no expert in JS or have much experience with Piwik so bare with me. I have three test websites linked to piwik:

w1 - http://localhost:8080/display/w1/
w2 - http://localhost:8080/display/w2/
w3 - http://localhost:8080/display/w3/

Currently if I ONLY embed the w1 tracking code in my js macro, it still shows +1 view if I visit w2 and w3. I tried altering the cookies with setCookieDomain (below) but it didn’t seem to do anything. Under the webpages, I have children pages as well so …/display/w1/page1. Any ideas to fix my problem would be greatly appreciated.


<!-- Piwik -->
<script type="text/javascript">
var pkBaseURL = (("https:" == document.location.protocol) ? "https://localhost/piwik/" : "http://localhost/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);

var piwiktracker = Piwik.getTracker(pkBaseUrl, 1);
piwiktracker.setCookieDomain('http://localhost:8080/display/w1/*');
piwiktracker.setDomains('http://localhost:8080/display/w1/*'); domains
piwiktracker.trackPageView();
piwikTracker.enableLinkTracking();
} catch( err ) {}
</script><noscript><p><img src="http://localhost/piwik/piwik.php?idsite=1" style="border:0" alt="" /></p></noscript>
<!-- End Piwik Tracking Code -->

Thanks!
Daniel


#2

Hey datran.

What you are describing is not a subdomain, just a different path on the same domain.
(Please read this: Subdomain - Wikipedia )

Also, setCookieDomain() only accepts a domain name (no protocol, port or path)

If you want to separate stats for these three web sites, I would suggest creating a Website in Piwik for each of your sites. They will then have different tracking codes (You have to put the unique tracking code on each site, w1, w2 and w3 will all be different.)


#3

Hey littleguy,

Thanks for the prompt response!

Oh, I guess my terminology was wrong. When you say create a website in Piwik for each of my sites, do you mean going to settings --> websites --> add a new website? If so, I’ve already added the three websites as follows:

Id:1
Name: w1
URLs:ci0000000078424:8080/display/w1
…(etc for the rest)

Id:2
Name: w2
URLs: ci0000000078424:8080/display/w2

Id:3
Name: w3
URLs: ci0000000078424:8080/display/w3

and each have their own View Tracking Code, it’s just when I embed say ONLY ‘w1’ into my webpage, if I visit w2 or w3 it still adds +1 view to w1 (even though i didnt call the w2 or w3 tracking code)

Thanks for the help,
Daniel


#4

Hey!

Use only the standard tracking code (Under Websites -> View tracking code), don’t add or remove anything to it.

If that does not work, please provide the three different tracking codes, exactly as you are using them.

[quote=datran]
Hey littleguy,

Thanks for the prompt response!

Oh, I guess my terminology was wrong. When you say create a website in Piwik for each of my sites, do you mean going to settings --> websites --> add a new website? If so, I’ve already added the three websites as follows:

Id:1
Name: w1
URLs:ci0000000078424:8080/display/w1
…(etc for the rest)

Id:2
Name: w2
URLs: ci0000000078424:8080/display/w2

Id:3
Name: w3
URLs: ci0000000078424:8080/display/w3

and each have their own View Tracking Code, it’s just when I embed say ONLY ‘w1’ into my webpage, if I visit w2 or w3 it still adds +1 view to w1 (even though i didnt call the w2 or w3 tracking code)

Thanks for the help,
Daniel[/quote]


(vipsoft) #5

You need to use setCookiePath.


#6

Hey littleguy,

Basically I was just trying to test 1 of the tracking codes so I only used the w1 tracking code seen on websites --> view tracking code. I placed only that code into a javascript macro and ran the macro on all three sites. Ideally what I wanted to happen was that although all three sites ran that macro, only w1 would get +1 views because the macro only has w1 tracking code. Could this issue be because I’m using a macro to call the javascript?

Thanks
Daniel


#7

Hi Vipsoft,

I was searching through cookiePath and all I found was from http://piwik.org/docs/javascript-tracking/:

[…]
// The idSite Y will be different from other user pages
tracker = Piwik.getTracker(pkBaseUrl, Y);
tracker.setCookiePath(’/user/MyUsername’);
tracker.trackPageView();
[…]

Not sure why I’d need username configurations? Or is there another way to implement CookiePath? An example would be awesome,

Thanks!
Daniel


(vipsoft) #8

For pages under /display/w1, you’d use:

tracker.setCookiePath(’/display/w1’) ;

Similarly for w2, w3,… This means the tracking cookie is isolated by path (instead of domain).

Your current tracking cookie is at “/” (web root), so you’ll have to clear your cookies before you try this.