Async tag and multiple siteids?

Hi,

First: I’m really new to Piwik :slight_smile:

I was planning if I would use Piwik with async tag so that it would add pageview to two websites (one being the whole server, and the other the current website).

Async api has setSiteId, can that be called multiple times and trackPageView also? If it can, what happens if there is some setCustomVariable/setDocumentTitle/setCookieDomain/setDomains calls before that?

If this question is hard to understand I’ll give a javascript example, would this work:


var _paq = _paq || [];
(function(){
    var u=(("https:" == document.location.protocol) ? "https://stats.example.org/" : "http://stats.example.org/");
// global websiteid
    _paq.push(["setSiteId", 19]);
    _paq.push(["setTrackerUrl", u+"piwik.php"]);
    _paq.push(["setCustomVariable", "1", "sex", "1", "page"]);
    _paq.push(["setCustomVariable", "2", "age", "3", "page"]);
    _paq.push(["setDocumentTitle", document.domain + "/" + document.title]);
    _paq.push(["setCookieDomain", "*.example.org"]);
    _paq.push(["setDomains", "*.example.org"]);
    if (!window.location.pathname.match(/^\/(admin|radmin)\//))
    {
    	_paq.push(["trackPageView"]);
    }
// current sites websiteid
    _paq.push(["setSiteId", 4142]); // did this reset custom variables etc?
    _paq.push(["setTrackerUrl", u+"piwik.php"]);
    if (!window.location.pathname.match(/^\/(admin|radmin)\//))
    {
    	_paq.push(["trackPageView"]);
    }
// link tracking, what should this do? for last one? or both?
    _paq.push(["enableLinkTracking"]);
    var d=document,
        g=d.createElement("script"),
        s=d.getElementsByTagName("script")[0];
        g.type="text/javascript";
        g.defer=true;
        g.async=true;
        g.src=u+"piwik.js";
        s.parentNode.insertBefore(g,s);
})();

And if it isn’t possible, would it be possible in future? Or is there a some other way to archive what I’m trying to do. Like having websites which have “subwebsites” or something.

The goal is to get whole server statistics to one login(user) and each individual website can also have a one login(user) to see those statistics.

I don’t think it would be so nice to have the whole server login(user) to have access to all the other websites in the server and there isn’t any combined reports, or are there? But I know that this way would be possible to implement.

Technically it should work. Check the http requests are correct using FIrebug extension.
If you find a problem please create a ticket or post here.

Hi,

Tested that a little. Seems to work with some restrictions.

If I set CustomVariables they are set to the other request also, I would probably need to deleteCustomVariable them in the between. Link Tracking will work only for the second setSiteId. Generates two requests to Piwik (understandable, but would have liked only one for the efficiency). Have to think would I like to have two requests done, but at least it can be done, but as it does two requests it would have been all the same to just use two different tags with own _paq array.

This is the code in which came up. siteId 23 is users websiteid and 20 is the global one.


<script type="text/javascript">
var _paq = _paq || [];
(function(){
    var u=(("https:" == document.location.protocol) ? "https://stats.example.org/" : "http://stats.example.org/");
    _paq.push(["setSiteId", 23]);
    _paq.push(["setTrackerUrl", u+"piwik.php"]);
    _paq.push(["setCustomVariable", "1", "sex", "1", "page"]);
    _paq.push(["setCustomVariable", "2", "age", "3", "page"]);
    if (!window.location.pathname.match(/^\/(admin|radmin)\//)) _paq.push(["trackPageView"]);
    _paq.push(["setSiteId", 20]);
    _paq.push(["setTrackerUrl", u+"piwik.php"]);
    _paq.push(["setDocumentTitle", document.domain + "/" + document.title]);
    _paq.push(["setDomains", "*.example.org"]);
    if (document.domain.match(/example.org$/)) _paq.push(["setCookieDomain", ".example.org"]);
    if (!window.location.pathname.match(/^\/(admin|radmin)\//)) _paq.push(["trackPageView"]);
    _paq.push(["enableLinkTracking"]);
    var d=document,
        g=d.createElement("script"),
        s=d.getElementsByTagName("script")[0];
        g.type="text/javascript";
        g.defer=true;
        g.async=true;
        g.src=u+"piwik.js";
        s.parentNode.insertBefore(g,s);
})();
</script>

Ok, please wait a few days for the next piwik release, then test agian. if you still experience issues please post here the full code to reproduce the issue + description of issue, thanks :slight_smile: