Ticket #355 (closed Bug: fixed)
piwik_log() kills the DOM when called: need new clean OO version of the JS tag
| Reported by: | remy.damour | Owned by: | vipsoft |
|---|---|---|---|
| Priority: | critical | Milestone: | Piwik 0.4 |
| Component: | Core | Keywords: | |
| Cc: | tecumtah@… | Sensitive: | no |
Description (last modified by matt) (diff)
Hi,
First, thanks for Piwik, it look greats, I'm sure it will even get better. Second, I filled this ticket as bug, because I did not expect piwik.js->piwik_log() to wipe out my entire DOM when called once DOM has been loaded.
Could it be possible to remove any call to document.write or document.writeln from within piwik.js (or make them optional, or put them into generated javascript inserted on each page)?
The reason is the following:
- I don't like having javascript within html doc, I prefer to have all my js code in dedicated .js files => I moved js code into outside script
(benefit: code cleaner + most importantly does not interfer with page execution (on my configuration, piwik.js is located on another hostname => my page load freezes up until the script piwik.js is loaded if I use javascript tags, with the consequence of delaying dom load and other js code execution for several seconds).
- when you call document.write/document.writeln once your dom has been loaded, it clears all page content => calling piwik_log() once dom is loaded clears all page content
If you could simply remove "document.writeln('<img src="'+_pk_src+'" alt="Piwik" style="border:0" />');" from within piwik.js (or make it optional using a parameter on piwik_log function), it would enhance a lot piwik flexibility (and make my day :-)).
Below is the js code I use (based on mootools1.2) to load piwik.js and call piwik_log from external .js file once all DOM is loaded (maybe it can be useful to other people):
window.addEvent('domready', function() {
function logPiwikData() {
try {
var piwik_loaded = !!piwik_log;
} catch (x) {
var piwik_loaded = null;
}
if (piwik_loaded) {
piwik_log.apply(this, arguments);
} else {
arguments.callee.delay(500, this, arguments); // piwik.js not loaded yet
}
}
var pkBaseURL = (("https:" == document.location.protocol) ? "https://piwik.qc4web.com/" : "http://piwik.qc4web.com/");
var piwik_action_name = document.title;
var piwik_idsite = 1;
var piwik_url = pkBaseURL + "piwik.php";
new Element('script').set('src', pkBaseURL + 'piwik.js').set('type','text/javascript').injectInside(document.body);
logPiwikData(piwik_action_name, piwik_idsite, piwik_url);
});
If you try it without commenting out document.writeln call from piwik.js, all your page content is wiped out. Once it's commented, everything works smoothly.
Regards, Remy

