Error when Adblock enabled


(dergringo) #1

Hi. I’m using piwik in combination with the wordpress plugin. I’ve already informed the author of the plugin but I think you might be interested in too.

The following case is required that an javascript error occures:
The user has Firefox with Adblock and Dr. Evil’s Filter List (http://maltekraus.de/Firefox/adblock.txt) enabled. This list is widely used by German speaking users.

The list blocks “/piwik.js”. But does not prevent the execution of the javascript tag part of piwik.

So when piwik.js was not loaded the tag part throws an error because of undefined vars/functions and so prevents the further execution of any javascript that might would have been executed on the rest of the page.

I temporarily fixed this in the following way (fix is for the plugin, not for piwik itself):

<!-- Piwik code inserted by Piwik Analytics Wordpress plugin by Jules Stuifbergen http://blog.jongbelegen/piwik -->
                <script language="javascript" src="<?php echo $options["jsurl"]; ?>" type="text/javascript"></script>
                <script type="text/javascript">
                <!--
                if (typeof _pk_install_tracker == "undefined") {
                    $('footer').appendChild(new Element('img', {
                        'src': '<?php echo $options["phpurl"] . "?idsite=" . $options["siteid"]; ?>',
                        style: 'border:0',
                        alt: 'piwik'
                    }));
                }
                else
                {
                    piwik_action_name = document.title;
                <?php if ( ! $options["dltracking"]) { ?>
                    piwik_install_tracker = 0;
                <?php } elseif ($options["dlextensions"] != '7z|aac|avi|csv|doc|exe|flv|gif|gz|jpe?g|js|mp(3|4|e?g)|mov|pdf|phps|png|ppt|rar|sit|tar|torrent|txt|wma|wmv|xls|xml|zip' ) { ?>
                    piwik_download_extensions = '<?php echo $options["dlextensions"]; ?>';
                <?php } ?>
                    piwik_idsite = <?php echo $options["siteid"]; ?>;
                    piwik_url = '<?php echo $options["phpurl"]; ?>';
                    piwik_log(piwik_action_name, piwik_idsite, piwik_url);
                }
                //-->
                </script><object>
                <noscript><p>Web analytics <img src="<?php echo $options["phpurl"] . "?idsite=" . $options["siteid"]; ?>" style="border:0" alt="piwik"/></p>
                </noscript></object>
                <!-- /Piwik -->

The important part is:

if (typeof _pk_install_tracker == "undefined")
{
 (add the static image for tracking)
}
else
{
 (print default piwik code)
}

Regards

Philipp


(robocoder) #2

Rename piwik.js to something less detectable. Then change these files were the filename is hardcoded:

  • core/Tracker/javascriptTag.tpl
  • misc/testJavascriptTracker/page2.php
  • misc/testJavascriptTracker/index.php
  • plugins/CoreHome/templates/piwik_tag.tpl

(dergringo) #3

Thanks for the quick reply.

I suggest to add the possibility to set the js file name somewhere in config space. Because in this case I have to patch it after updating. And I tend to keep my apps up2date style_emoticons/<#EMO_DIR#>/smile.gif


(robocoder) #4

We’ll need more votes in favor of this one. (This feature request was previously marked wontfix.)


(pss7) #5

a confile filename flag makes sense - or block firefox users style_emoticons/<#EMO_DIR#>/wink.gif g


(pss7) #6

or is it possible to markthem seperatly?


(robocoder) #7

Another idea is to use mod_rewrite.

Doesn’t work because Adblock Plus picks up on this through the content policy filter.


(Matthieu Aubry) #8

I added your suggestion as a requirement for the new javascript tracking code. http://dev.piwik.org/trac/ticket/355#comment:18

A simple way to do this would be to surround the code by a try { } catch block.