Title: Google Analytics conversion tracking&#8230;
Last modified: August 22, 2016

---

# Google Analytics conversion tracking…

 *  Resolved [chasman](https://wordpress.org/support/users/chasman/)
 * (@chasman)
 * [11 years, 3 months ago](https://wordpress.org/support/topic/google-analytics-conversion-tracking/)
 * What’s the best way to track clicks of the affiliate links as a GA Conversion?
 * I have the code fragment:
 * **onClick=”_gaq.push([‘_trackEvent’, ‘Book’, ‘Link’, ‘Buy the eBook’]);”
 * But no idea how to deploy it…
 * [https://wordpress.org/plugins/amazon-link/](https://wordpress.org/plugins/amazon-link/)

Viewing 6 replies - 1 through 6 (of 6 total)

 *  Plugin Author [paulstuttard](https://wordpress.org/support/users/paulstuttard/)
 * (@paulstuttard)
 * [11 years, 3 months ago](https://wordpress.org/support/topic/google-analytics-conversion-tracking/#post-5774916)
 * Hi,
 * There is no easy way to do this at present, however add the following code fragment
   to your functions.php might work, I have not tested it:
 *     ```
       function alx_extras_add_link_ga($url){
            $url = str_replace('rel=', 'onClick="_gaq.push([\'_trackEvent\', \'Book\', \'Link\', \'Buy the eBook\']);" rel=', $url);
            return $url;
         }
         add_filter( 'amazon_link_template_get_link_open',  'alx_extras_add_link_class', 22, 1 );
         add_filter( 'amazon_link_template_get_rlink_open', 'alx_extras_add_link_class', 22, 1 );
         add_filter( 'amazon_link_template_get_slink_open', 'alx_extras_add_link_class', 22, 1 );
       ```
   
 * Paul
 *  Plugin Author [paulstuttard](https://wordpress.org/support/users/paulstuttard/)
 * (@paulstuttard)
 * [11 years, 3 months ago](https://wordpress.org/support/topic/google-analytics-conversion-tracking/#post-5774988)
 * Typos in the above, should of course be:
 *     ```
       function alx_extras_add_link_ga($url){
            $url = str_replace('rel=', 'onClick="_gaq.push([\'_trackEvent\', \'Book\', \'Link\', \'Buy the eBook\']);" rel=', $url);
            return $url;
         }
         add_filter( 'amazon_link_template_get_link_open',  'alx_extras_add_link_ga', 22, 1 );
         add_filter( 'amazon_link_template_get_rlink_open', 'alx_extras_add_link_ga', 22, 1 );
         add_filter( 'amazon_link_template_get_slink_open', 'alx_extras_add_link_ga', 22, 1 );
       ```
   
 * Paul
 *  Thread Starter [chasman](https://wordpress.org/support/users/chasman/)
 * (@chasman)
 * [11 years, 3 months ago](https://wordpress.org/support/topic/google-analytics-conversion-tracking/#post-5775245)
 * Okay I’m going to try this as I really need to track all outbound clicks to Amazon
   within Analytics… I’ve looked into it a bit more and realise the code fragment
   I gave you isn’t representative of actual use…
 * **_trackEvent(category, action, opt_label, opt_value, opt_noninteraction)**
 * **category (required)**
    The name you supply for the group of objects you want
   to track.
 * **action (required)**
    A string that is uniquely paired with each category, and
   commonly used to define the type of user interaction for the web object.
 * **label (optional)**
    An optional string to provide additional dimensions to 
   the event data.
 * **value (optional)**
    An integer that you can use to provide numerical data about
   the user event.
 * **non-interaction (optional)**
    A boolean that when set to true, indicates that
   the event hit will not be used in bounce-rate calculation.
 * So we need:
 * _trackEvent(‘Affil’, ‘Amazon’, $ASIN)
 * Where $ASIN is my placeholder for the ASIN of the link they actually clicked…
 * Is that doable?
 *  Plugin Author [paulstuttard](https://wordpress.org/support/users/paulstuttard/)
 * (@paulstuttard)
 * [11 years, 3 months ago](https://wordpress.org/support/topic/google-analytics-conversion-tracking/#post-5775251)
 * Hi,
 * Just change the code in the fragment I gave you use %ASIN% to add the product
   asin, and remember you need to escape the apostrophes.
 *     ```
       function alx_extras_add_link_ga($url){
            $url = str_replace('rel=', 'onClick="_trackEvent(\'Affil\', \'Amazon\', \'%ASIN%\');" rel=', $url);
            return $url;
         }
         add_filter( 'amazon_link_template_get_link_open',  'alx_extras_add_link_ga', 22, 1 );
         add_filter( 'amazon_link_template_get_rlink_open', 'alx_extras_add_link_ga', 22, 1 );
         add_filter( 'amazon_link_template_get_slink_open', 'alx_extras_add_link_ga', 22, 1 );
       ```
   
 *  Thread Starter [chasman](https://wordpress.org/support/users/chasman/)
 * (@chasman)
 * [11 years, 3 months ago](https://wordpress.org/support/topic/google-analytics-conversion-tracking/#post-5775256)
 * Cool! Cheers 🙂 I’ll get back to you with results…
 *  Thread Starter [chasman](https://wordpress.org/support/users/chasman/)
 * (@chasman)
 * [11 years, 3 months ago](https://wordpress.org/support/topic/google-analytics-conversion-tracking/#post-5775257)
 * Excellent… Goal Amazon Click is now showing on my GA Dashboard… thanks very much
   for the help and the excellent plugin.

Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘Google Analytics conversion tracking…’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/amazon-link_070606.svg)
 * [Amazon Link](https://wordpress.org/plugins/amazon-link/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/amazon-link/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/amazon-link/)
 * [Active Topics](https://wordpress.org/support/plugin/amazon-link/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/amazon-link/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/amazon-link/reviews/)

 * 6 replies
 * 2 participants
 * Last reply from: [chasman](https://wordpress.org/support/users/chasman/)
 * Last activity: [11 years, 3 months ago](https://wordpress.org/support/topic/google-analytics-conversion-tracking/#post-5775257)
 * Status: resolved