[PHP Help] Wordpress Plugin - Nextgen Gallery

Discussion in 'General Programming Chat' started by twistedtrick, Mar 24, 2014.

  1. twistedtrick

    twistedtrick Power Member

    Aug 21, 2009
    Likes Received:
    United States
    Right now I am working with a client who wants to track outbound clicks on their sponsor logos.

    In the footer of the website, I am able to manually add the tracking code to each link without any issue. However, on the sidebar of the site the client wanted to rotate the logos so we went with NextGen Gallery to handle the image rotation, and then modified the code a little so that the gallery widget thumbnails could be hyperlinked to an external URL instead of just the image itself.

    I believe I just have an issue with the PHP syntax because I am not a programmer at all. Any help would be greatly appreciated!

    Here is the working code, that is NOT tracking Analytics Clicks:
    $out = '<a href="' . $image->alttext . '" title="' . $description . '" ' . $thumbcode .'>';
    Here is my attempt at adding Event Tracking to this code, but I receive syntax errors I believe due to my improper usage of single, double quotes and escape characters. My goal is to place each link in the "outbound-widget-sponsor" Event Category in Google Analytics, and give the Event Action as the URL (with the . $image->alttext . variable).

    $out = '<a href="' . $image->alttext . 'onclick="javascript:_gaq.push([\'_trackEvent\',\'outbound-widget-sponsor\',\'' . $image->alttext . '\'''" title="' . $description . '" ' . $thumbcode .'>';
  2. MrBlue

    MrBlue Senior Member

    Dec 18, 2009
    Likes Received:
    Web/Bot Developer
    Looks like your issue is with some missing and misplaced apostrophes. Also, shouldn't the first occurrence of $image->alttext be replaced with a url and not a alt-text?