New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
piwik_log() kills the DOM when called: need new clean OO version of the JS tag #5775
Comments
You are quite right that this is a bug. One solution could be to create an image in Javascript and append this image to the DOM, avoiding the document.write Actually we would like to rewrite the whole piwik.ks javascript code to use an object oriented structure. If someone would be ready to help on this story, let me know! :) |
Hi Matt, I’ve made such implementation. It’s quite long to write it all here, I’ve set it up in my blog: http://qc4blog.com/?p=114 You can use the source code as you want. I hope you will find it usefull. By the way, when generating code to be inserted within all pages, it could be useful to add “?idsite=N” to <noscript> url so that it will get to correct id site. Regards, |
Note: it obviously needs heavy testing |
See also the change suggested in the piwik-hackers mailing list: http://lists.piwik.org/pipermail/piwik-hackers/2008-August/000337.html that would make the tracker work in XHTML |
See also: Google analytics Tracking API seems really powerful. We wouldn’t need so much but the concept is good. http://code.google.com/apis/analytics/docs/gaJSApi.html |
Also consider to build in “time tracking” to show a report of the speed of the website, enabled via a boolean in the javascript. Does the tracker need to be at top? |
See also microsoft javascript API: https://help.live.com/help.aspx?mkt=en-us&project=adCenter_Analytics_rtw&querytype=keyword&query=7101yek&tmt=frmReport&domain=adcenter.microsoft.com&format=b1 http://analytics.live.com/Analytics/msAnalytics.js |
see also yahoo JS: http://web.analytics.yahoo.com/indextools.js |
We should also consider reusing the open source google analytics flash library to track piwik flash events: http://code.google.com/apis/analytics/docs/flashTrackingSetupFlash.html |
Interesting suggestion from the forums, maybe worth adding to the requirements: I am newbie in JavaScript, but is it possible create “google analytics like” javascript code? I mean: insert only short script tag(s) with link in monitoring pages like this <script src=“http://my_site.com/piwik.js” type=“text/javascript”></script> |
And perhaps some ideas from http://sourceforge.net/projects/subspace/ |
As reported on piwik-hacker, piwik.js doesn’t recognize <AREA> elements. (Workaround is to use <A>.) |
Attachment: Remy Damour work on rewriting piwik.js in OO |
microsoft analytics readable code can be found on http://utilitybase.com/paste/11219 (for information only) |
- we have to keep backward compatibility by providing old functions as bridges to the new OO class ``` |
- as a new requirement, we shall make sure that Piwik doesn’t produce javascript error when the piwik.js is blocked by ad-blocking extensions. Currently the code tries to call piwik_log which is not defined and results in a javascript error. [See forum for more info](whos.amung.us). |
See also ticket #549. |
- new requirement: piwik.js would provide a` This is open to suggestions.. |
for interest, [Yahoo Web Analytics Javascript API](http://help.yahoo.com/l/us/yahoo/smallbusiness/store/analytics/advanced/advanced-02.html) |
has anyone figured out a way around this yet. I am attempting to implement tracking from within a swf file and the only thing keeping this from completion is that the DOM blanks out after the piwik_log is called |
@doodlez, you might find this useful: http://www.qc4blog.com/?p=114 Regards, Remy |
Replying to doodlez:
@doodlez, you might find this useful: http://www.qc4blog.com/?p=114 oop js file (not using document.write): http://qc4blog.com/wp-content/uploads/2008/09/piwik_oop-029.js Regards, Remy |
I attempted to integrate your code, but it didn't appear to be tracking. |
this is what I attempted to implement: <script language="javascript" src="http://www.****.com/piwik/piwik_oop-0.2.9-min.js" type="text/javascript"></script> <noscript><p>Web analytics <img src="http://www.****.com/piwik/piwik.php?idsite=1" style="border:0" alt="piwik"/></p> |
this will be the main new feature in Piwik 0.4 release. |
(In [1151]) fixes #5775 - OO version of piwik.js which no longer modifies DOM; |
(In [1157]) refs #5775 - minor changes per review |
(In [1177]) - refs #5775 now displaying the new OO JS tag by default in install & in admin UI + showing some help + renaming the "js code" to consistent "JavaScript Tracking Tag" |
(In [1185]) refs #5775 - accommodate malformed URIs that contain an illegal space |
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:
1. 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).
2. 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):
```
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);window.addEvent(‘domready’, function() {
});
```
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
The text was updated successfully, but these errors were encountered: