Viewing 9 replies - 1 through 9 (of 9 total)
  • Great question. I am looking for this answer too.

    Yeah. I want to do the same thing.

    Here is what I did…
    Went to line 90 of nav-menu-template.php:

    $item_output .= '<a'. $attributes .'>';

    and modified it to add what I wanted. In this case I needed to add a Google Analytics onclick event to enable cross domain tracking:

    onclick="_gaq.push([\'_link\', this.href]); return false;"

    The final product is:

    $item_output .= '<a'. $attributes .' onclick="_gaq.push([\'_link\', this.href]); return false;" >';

    Thanks for the info. very helpful. I’m trying to do the same thing with my Google analytics to track across multiple domains.

    I added the code as described above, but how do I know if it’s working? When I hove over the the menu item, it still shows the basic URL and when I click on it, nothing different seems to happen.

    Also does using this.href replicate putting the URL back into the the code the way that $attributes does?

    To see what’s going on in your cookies in Firefox go to:
    Tools > Options > Privacy > Show Cookies

    From there you can see if the google _utma _utmb and _utmz values are set. If they are set across domains you know your links are working properly.

    I don’t know about this.href vs $attributes

    Thanks. I checked around and found some other sources using the this.href in the code. But one thing additional you have is backslashes around the ‘_link’. Is that intentional for wordpress? According to the google references, there are no backslashes in their code. I’m not sure if that will make a difference in how this works.

    <a href="http://store.firstfairway.com/golf-clubs-c5.aspx" onclick="_gaq.push(['_link', this.href]); return false;">CLUBS</a>

    \’_link\’ versus ‘_link’?

    Nevermind. I just figured it out. the backslash is an escape in php so it will literally invoke the single quote.

    Thanks @alreadysetup for the code tweak !
    But do somebody know another way without changing WP core code ? (this could be unsustainable on WP updates…

    palbertus…I’m still looking for a better solution too. I actually have this code added in the nav-menu-template.php as described above, but it doesn’t work.

    They way I can tell is that if I click a link in the body of one of my wordpress pages that has the proper onclick syntax added to the hyperlink, I can see the utma, utmb, and utmz values getting passed to the new domain I’m linking too.

    But if I click on a link from the wordpress menu, those values are not getting passed. I’ve checked the code I updated in nav-menu-template.php multiple times and it’s correct as posted here, but doesn’t seem to function for me.

    I’m going to check with a developer. Ideally this would be best handled as plug in. Seems like an easy update though.

    Let me know if you have any success with it, maybe I’m doing something wrong.

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘add onclick javascript into custom menu’ is closed to new replies.