1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

[PHP Help] Wordpress Plugin - Nextgen Gallery

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

  1. twistedtrick

    twistedtrick Power Member

    Joined:
    Aug 21, 2009
    Messages:
    654
    Likes Received:
    377
    Location:
    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:
    Code:
    $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).

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

    MrBlue Senior Member

    Joined:
    Dec 18, 2009
    Messages:
    950
    Likes Received:
    662
    Occupation:
    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?