Recording to multiple idsites with JS code

Hi,

We are on 2.9.1. We are want to use the JS code to populate two idsites. The first below is to an
individual site and the second is the an “all” site. In other words, each individual sites we want to track
have there own individual site and all sites have the second block of JS code. Our problem is, that nothing
is being recorded on the “all” group, the second one. We changed the variable _paq to _paq2 in the second
group, because IE gave an error about duplicate variable being declared. Below is the code. Any ideas what
we should be doing?

Thanks,
Douglas

Hi there, to store data in two separate websites you must use the old non-asynchronous technique, see: JavaScript Tracking Client: Integrate - Matomo Analytics (formerly Piwik Analytics) - Developer Docs - v3

Hi,

I am still having trouble. I have tried both:

Hello
Bye

and:

Hello
Bye

and the last one above without the tracking for #51 (pt2 ones). In non of the three cases do I get anything
recorded in the piwik db that I can tell, at least when I do:

select count() from piwik_log_link_visit_action WHERE idsite = 50;
select count(
) from piwik_log_link_visit_action WHERE idsite = 51;

Any ideas?

Thanks,
Douglas

And do you see data recorded when you put only one code in the page?

If you remove the TRY / CATCH, do you see an error in the javascript console?

I had tried it with just one, via commenting the other out. I did not try removing the try/catch yet. Thanks for
suggesting this, I should have already thought of that, but I have been out of JS programming for a while.
I stripped it down to a minimum:

Hello
Bye

The function piwikAsyncInit is not defined, which of course makes sense since I did not include piwik.js. I will look
up how to include that and see what happens.

Thanks for the help!
Douglas

Ok, I tried:

Hello
Bye

and it did not work. So far, I do not see an error, but it fails in piwik.AsysncInit somehow. If I change the code to:

Hello
Bye

It works fine, except it is not async. I am still re-learning the debugger, so maybe I will find out more soon. It also does not
work if I leave the piwikAsyncInit in and take out the try/catch. So, it is something about the call to piwikAsyncInit.

[added]
And one other question: I noticed in the original response, you said ‘the old non-asynchronous technique’. Yet the link you sent
me to had window.piwikAsyncInit() in it, which the only reference I have found so far is in the non-mini piwik.js file:

if (window && window.piwikAsyncInit) {
window.piwikAsyncInit();
}

and once in the comments a ways above the above section of code.

Thanks,
Douglas

Instead of trying to use window.piwikAsyncInit(), I used the async option in script:

Hello
Bye

From what I see so far, it appears to be working… Does anyone see any drawbacks?

It appears to be working in the test cases. New question:

The code I was using was designed for all sites to go to their individual recording idsites and also go
to an ‘all’ idsite. It was pouplating the individual sites, but not the ‘all’ site. We plan on implementing
the api code tomorrow that seems to be working fine in the test environment. My question is can the
data from the individual idsites be accumulated into the ‘all’ site or do I just need to clear all the data
out for all the sites? We basically need the data to match instead of the ‘all’ just starting now and the
individual ones have a longer history.

Thanks,
Douglas