Google Tracking for Amazon Recommendations

Creating and modifying plugins.
Post Reply
danst0
Regular
Posts: 197
Joined: Tue Jul 13, 2004 10:50 am

Google Tracking for Amazon Recommendations

Post by danst0 »

Hi,

I would suggest the following patch for the amazon sidebar plugin.

Code: Select all

Binary files serendipity_plugin_amazon/.DS_Store and neu_serendipity_plugin_amazon/.DS_Store differ
diff -rNu serendipity_plugin_amazon/lang_en.inc.php neu_serendipity_plugin_amazon/lang_en.inc.php
--- serendipity_plugin_amazon/lang_en.inc.php	2009-09-13 02:30:42.000000000 +0700
+++ neu_serendipity_plugin_amazon/lang_en.inc.php	2011-07-31 14:58:00.000000000 +0700
@@ -11,6 +11,8 @@
 @define('PLUGIN_AMAZON_PROP_TITLE',         "Title");
 @define('PLUGIN_AMAZON_PROP_TITLE_DESC',    "Title to display in the Sidebar");
 @define('PLUGIN_AMAZON_NEW_WINDOW',         "Open links in new windows");
+@define('PLUGIN_AMAZON_TRACK_GOOGLE',       "Track Clicks using Google Analytics");
+@define('DESC_PLUGIN_AMAZON_TRACK_GOOGLE',  "Google Analytics Plugin needed.");
 @define('PLUGIN_AMAZON_SMALL_MED',          "Thumbnail size to display");
 @define('PLUGIN_AMAZON_SMALL',              "Small");
 @define('PLUGIN_AMAZON_MEDIUM',             "Medium");
diff -rNu serendipity_plugin_amazon/serendipity_plugin_amazon.php neu_serendipity_plugin_amazon/serendipity_plugin_amazon.php
--- serendipity_plugin_amazon/serendipity_plugin_amazon.php	2009-10-05 02:31:12.000000000 +0700
+++ neu_serendipity_plugin_amazon/serendipity_plugin_amazon.php	2011-07-31 14:58:00.000000000 +0700
@@ -19,10 +19,10 @@
     function introspect(&$propbag) {
         $propbag->add('name',           PLUGIN_AMAZON_TITLE);
         $propbag->add('description',    PLUGIN_AMAZON_DESC);
-        $propbag->add('configuration',  array('title','server', 'newwindows', 'small_medium_large','button','asin','cnt','cache'));
+        $propbag->add('configuration',  array('title','server', 'newwindows', 'small_medium_large','button','asin','cnt','cache','tracking'));
         $propbag->add('author',         'Matthew Groeninger, (original plugin by Thomas Nesges)');
         $propbag->add('stackable',      true);
-        $propbag->add('version',        '1.21');
+        $propbag->add('version',        '1.22');
         $propbag->add('requirements',  array(
             'serendipity' => '0.8',
             'smarty'      => '2.6.7',
@@ -92,6 +92,12 @@
                 $propbag->add('radio_per_row', '1');
                 $propbag->add('default', 'small');
                 break;
+            case 'tracking':
+                $propbag->add('type',        'boolean');
+                $propbag->add('name',        PLUGIN_AMAZON_TRACK_GOOGLE);
+                $propbag->add('description', DESC_PLUGIN_AMAZON_TRACK_GOOGLE);
+                $propbag->add('default',     false);
+                break;
 
             default:
                 return false;
@@ -146,6 +152,7 @@
         } else {
            $content_out = $content;
         }
+        $content_out = str_replace('&', '&', $content_out);
         echo $content_out;
     }
 
@@ -171,14 +178,18 @@
                 if ($this->get_config('newwindows')) {
                    $target = ' target="_new" ';
                 }
+                $google_tracking = '';
+                if ($this->get_config('tracking') && class_exists('serendipity_event_google_analytics')) { 
+                    $google_tracking = "onclick=\"_gaq.push(['_trackEvent', 'Amazon', 'Click', '" . $strings['title'] . "']);\"";
+                }
                 $file_size = $this->get_config('small_medium_large','smallurl');
                 $content = '<div class="amazon_sidebar">';
                 if (isset($strings["$file_size"])) {
-                   $content .= '<a href="'.$strings['DETAILPAGEURL'].'" '.$target.'><img src="'.$strings["$file_size"].'"/></a>';
+                   $content .= '<a ' . $google_tracking . 'href="'.$strings['DETAILPAGEURL'].'" '.$target.'><img src="'.$strings["$file_size"].'"/></a>';
                 } else {
-                   $content .= '<a href="'.$strings['DETAILPAGEURL'].'" '.$target.'>'.PLUGIN_EVENT_AMAZONCHOOSER_NOIMAGE.'</a>'; 
+                   $content .= '<a ' . $google_tracking . 'href="'.$strings['DETAILPAGEURL'].'" '.$target.'>'.PLUGIN_EVENT_AMAZONCHOOSER_NOIMAGE.'</a>'; 
                 }
-                $content .= '<div class="amazon_sidebar_details"><a href="'.$strings['DETAILPAGEURL'].'" '.$target.'>'.$strings['title'].'</a></div>';
+                $content .= '<div class="amazon_sidebar_details"><a ' . $google_tracking . 'href="'.$strings['DETAILPAGEURL'].'" '.$target.'>'.$strings['title'].'</a></div>';
                 $content .= '</div>';
                 if (class_exists('Cache_Lite') && is_object($cache_obj)) {
                    $cache_obj->save($content,'amazonsidebar_'.$asin);
Would be great if someone could review and commit it!

Daniel
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: Google Tracking for Amazon Recommendations

Post by garvinhicking »

Hi!

Hm, I cannot apply this patch:

patching file lang_en.inc.php
patch: **** malformed patch at line 5: @define('PLUGIN_AMAZON_PROP_TITLE', "Title");

Can you provide a proper unified patch that I can simply either download or copy&paste and that works? :)

Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
danst0
Regular
Posts: 197
Joined: Tue Jul 13, 2004 10:50 am

Re: Google Tracking for Amazon Recommendations

Post by danst0 »

Don't know how this happened. This version works here.

Try this file perhaps it's a formatting issue with the code tag:
http://dl.dropbox.com/u/285107/patch.diff

Daniel
garvinhicking
Core Developer
Posts: 30022
Joined: Tue Sep 16, 2003 9:45 pm
Location: Cologne, Germany
Contact:

Re: Google Tracking for Amazon Recommendations

Post by garvinhicking »

Hi!

Great! Now it works! :)

Regards,
Garvin
# Garvin Hicking (s9y Developer)
# Did I help you? Consider making me happy: http://wishes.garv.in/
# or use my PayPal account "paypal {at} supergarv (dot) de"
# My "other" hobby: http://flickr.garv.in/
Post Reply