Skip to content

Commit

Permalink
Add simple Google Analytics plugin.
Browse files Browse the repository at this point in the history
  • Loading branch information
racke committed Aug 6, 2010
1 parent 3c29625 commit 2b2ab94
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 0 deletions.
2 changes: 2 additions & 0 deletions plugins/google_analytics/README
@@ -0,0 +1,2 @@
Please define your Google Analytics ID as GOOGLE_ANALYTICS_ID in the variable database
of your production system.
34 changes: 34 additions & 0 deletions plugins/google_analytics/code/google_analytics.tag
@@ -0,0 +1,34 @@
UserTag google_analytics Order function code
UserTag google_analytics Routine <<EOR
sub {
my ($function, $code) = @_;
my (@trans, $set, $out);

return unless $function eq 'transaction';

$Tag->perl({tables => 'transactions orderline'});

# transaction details
@trans = $Db{transactions}->get_slice($code, [qw/affiliate total_cost salestax shipping city state country/]);
unshift(@trans, $code);

$out = q{pageTracker._addTrans(
} . join(",\n", map {$Tag->jsqn("$_")} @trans)
. ");\n\n";

# orderline entries
$set = $Db{orderline}->query({sql => qq{select order_number,sku,description,'',price,quantity from orderline where order_number = $code}});
for (@$set) {
$out .= q{pageTracker._addItem(
} . join(",\n", map {$Tag->jsqn($_)} @$_)
. ");\n\n";
}

# complete transaction tracking
$out .= q{pageTracker._trackTrans();
};

return $out;
}
EOR

11 changes: 11 additions & 0 deletions plugins/google_analytics/components/google_analytics
@@ -0,0 +1,11 @@
[if var GOOGLE_ANALYTICS_ID]
<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
var pageTracker = _gat._getTracker("__GOOGLE_ANALYTICS_ID__");
pageTracker._trackPageview("__PAGEVIEW__[if cgi q]?q=[cgi q][/if]");
__TRACK__
</script>
[/if]
3 changes: 3 additions & 0 deletions plugins/google_analytics/google_analytics.info
@@ -0,0 +1,3 @@
name = Google Analytics
version = 1.0
author = Stefan Hornburg (Racke) <racke@linuxia.de>
4 changes: 4 additions & 0 deletions plugins/google_analytics/plugin.cfg
@@ -0,0 +1,4 @@
Message Loading Google Analytics plugin.

Variable CURPLUGIN google_analytics
include plugins/default.cfg

0 comments on commit 2b2ab94

Please sign in to comment.