0
Welcome Guest! Login
0 items Join Now

Add onclick to "external link" menu links

  • Add onclick to "external link" menu links

    Posted 13 years 5 months ago
    • I need to add the following code to all "external link" menu links in order to track google analytics across multiple domains:
      onclick="pageTracker._link(this.href); return false;"

      I've been trying for hours. There is 1 extension, but it hasn't been supported for a few years.

      I don't mind hacking the core files. I tried hacking modules/mod_mainmenu/helper.php, but it seems the Modulus template is overriding it and I can't figure out where. I'm on Joomla 1.5.

      Any ideas?

      Thanks very much,
      Phil
    • Last Edit: 13 years 5 months ago by Phil Raymond.
  • Re: Add onclick to "external link" menu links

    Posted 13 years 5 months ago
    • I know this is not a common issue I'm dealing with here, but does anyone have any ideas of where I might start?

      Thanks,
      Phil
  • Re: Add onclick to "external link" menu links

    Posted 13 years 5 months ago
    • Sorry for the bump, but I still haven't solved this. I think the RT forum is the best place for me to ask, since I'll need to hack a RT file.

      Phil
  • Re: Add onclick to "external link" menu links

    Posted 13 years 5 months ago
    • Sorry, I've been trying it on my own for days, but I can't get it.
  • Re: Add onclick to "external link" menu links

    Posted 13 years 5 months ago
    • Bump (paying customer for a few years now).
    • Henning's Avatar
    • Henning
    • Preeminent Rocketeer
    • Posts: 29362
    • Thanks: 954
    • Volunteer

    Re: Add onclick to "external link" menu links

    Posted 13 years 5 months ago
    • I fear I cant really help you.

      1. the overrides for modules are in the "html"-folder of the template. Check RokNav for this
      2. I could think of using ReReplacer from nonumber.nl for this.
      A very Handy component ...
  • Re: Add onclick to "external link" menu links

    Posted 13 years 5 months ago
    • Thanks for the help. ReReplacer looks useful, but for anyone else trying to do the same thing, I actually did a hack instead. I hacked templates/rt_modules_j15/html/mod_roknavmenu/themes/gantry_fusion/layout.php (Joomla 1.5.23) and changed this line:
      <a <?php if($item->hasLinkClasses()):?>class="<?php echo $item->getLinkClasses().$activeToTop;?>"<?php endif;?> <?php if($item->hasLink()):?>href="<?php echo $item->getLink();?>"<?php endif;?> <?php if($item->hasTarget()):?>target="<?php echo $item->getTarget();?>"<?php endif;?> <?php if ($item->hasAttribute('onclick')): ?>onclick="<?php echo $item->getAttribute('onclick'); ?>"<?php endif; ?><?php if ($item->hasLinkAttribs()): ?> <?php echo $item->getLinkAttribs(); ?><?php endif; ?>>

      to this:
      <a <?php if($item->hasLinkClasses()):?>class="<?php echo $item->getLinkClasses().$activeToTop;?>"<?php endif;?> <?php if($item->hasLink()):?>href="<?php echo $item->getLink();?>"<?php endif;?> <?php if($item->hasTarget()):?>onclick="pageTracker._link(this.href); return false;"<?php endif;?> <?php if ($item->hasAttribute('onclick')): ?>onclick="<?php echo $item->getAttribute('onclick'); ?>"<?php endif; ?><?php if ($item->hasLinkAttribs()): ?> <?php echo $item->getLinkAttribs(); ?><?php endif; ?>>

      The part I changed was this:
      target="<?php echo $item->getTarget();?>"

      to this (note I was using the old analytics code):
      onclick="pageTracker._link(this.href); return false;"

      and then I set my external link in the Joomla menu manager to open in a 'New Window with Browser Navigation'. Kind of a weird workaround, but it worked great.

      (And then after all of this work, I abandoned trying to get cross-domain tracking working, but the above method does work).

      Phil
    • Henning's Avatar
    • Henning
    • Preeminent Rocketeer
    • Posts: 29362
    • Thanks: 954
    • Volunteer

    Re: Add onclick to "external link" menu links

    Posted 13 years 5 months ago
    • Thanks for posting this. Looks like valid solution to me. Your are not hacking the module or the J-core. You have modified the override – that's the way to tackle things like this :-)

Time to create page: 0.063 seconds