[wellwell-devel] [wellwell] Add simple Google Analytics plugin.

Stefan Hornburg wellwell-devel at rt.icdevgroup.org
Fri Aug 6 12:00:52 UTC 2010


commit 2b2ab949eb60c4c5498ac10e80bc34035fd45fa8
Author: Stefan Hornburg (Racke) <racke at linuxia.de>
Date:   Fri Aug 6 14:00:23 2010 +0200

    Add simple Google Analytics plugin.

 plugins/google_analytics/README                    |    2 +
 plugins/google_analytics/code/google_analytics.tag |   34 ++++++++++++++++++++
 .../google_analytics/components/google_analytics   |   11 ++++++
 plugins/google_analytics/google_analytics.info     |    3 ++
 plugins/google_analytics/plugin.cfg                |    4 ++
 5 files changed, 54 insertions(+), 0 deletions(-)
---
diff --git a/plugins/google_analytics/README b/plugins/google_analytics/README
new file mode 100644
index 0000000..c33295c
--- /dev/null
+++ b/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.
diff --git a/plugins/google_analytics/code/google_analytics.tag b/plugins/google_analytics/code/google_analytics.tag
new file mode 100644
index 0000000..e431645
--- /dev/null
+++ b/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
+
diff --git a/plugins/google_analytics/components/google_analytics b/plugins/google_analytics/components/google_analytics
new file mode 100644
index 0000000..0b67daa
--- /dev/null
+++ b/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]
diff --git a/plugins/google_analytics/google_analytics.info b/plugins/google_analytics/google_analytics.info
new file mode 100644
index 0000000..de98921
--- /dev/null
+++ b/plugins/google_analytics/google_analytics.info
@@ -0,0 +1,3 @@
+name = Google Analytics
+version = 1.0
+author = Stefan Hornburg (Racke) <racke at linuxia.de>
diff --git a/plugins/google_analytics/plugin.cfg b/plugins/google_analytics/plugin.cfg
new file mode 100644
index 0000000..a3360f2
--- /dev/null
+++ b/plugins/google_analytics/plugin.cfg
@@ -0,0 +1,4 @@
+Message Loading Google Analytics plugin.
+
+Variable CURPLUGIN google_analytics
+include plugins/default.cfg



More information about the wellwell-devel mailing list