Block Performancing Metrics logging from specific paths in Drupal

Well, I guess you don’t want Performancing Metrics logging all your jumping around in the admin panel, right? Solving this is actually quite simple. I assume that you have added Metrics’ <script> in your theme’s page.tpl.php. The cool thing about PHP template engines like phptemplate is, that you can probably most of the functions available through the API of whatever CMS you’re using.

In Drupal’s case this also means, that the arg(int) function works. So to block Metrics from the admin panel, you could simply replace your previous script-reference with something like that:

<?php if(arg(0) != 'admin'):?>
<script id="stats_script" type="text/javascript" src=""></script>
<?php endif; ?>

Nothing really fascinating about this, but it’s simply nice to have all this stuff also available in the templates and this is just IMO a quite good use for it since Metrics has nothing to do in my admin section.

With arg(int) being available you could naturally do the same thing with other paths like for example blocking it from specific nodes with code like:

<?php if(!(arg(0) == 'node' && arg(1)=='2')): ?>
<?php endif; ?>
comments powered by Disqus