From 8cf2b06e53882b29bf32a87fc5a6967a81f4f9d7 Mon Sep 17 00:00:00 2001 From: Jermolene Date: Mon, 25 Nov 2013 23:14:12 +0000 Subject: [PATCH] Move Google Analytics integration into a proper plugin --- .../system/GoogleAnalyticsAccount.tid | 3 ++ .../tiddlers/system/GoogleAnalyticsDomain.tid | 3 ++ .../tw5.com/tiddlers/system/analytics.tid | 14 -------- editions/tw5.com/tiddlywiki.info | 1 + .../googleanalytics/googleanalytics.js | 32 +++++++++++++++++++ .../tiddlywiki/googleanalytics/plugin.info | 6 ++++ 6 files changed, 45 insertions(+), 14 deletions(-) create mode 100644 editions/tw5.com/tiddlers/system/GoogleAnalyticsAccount.tid create mode 100644 editions/tw5.com/tiddlers/system/GoogleAnalyticsDomain.tid delete mode 100644 editions/tw5.com/tiddlers/system/analytics.tid create mode 100644 plugins/tiddlywiki/googleanalytics/googleanalytics.js create mode 100644 plugins/tiddlywiki/googleanalytics/plugin.info diff --git a/editions/tw5.com/tiddlers/system/GoogleAnalyticsAccount.tid b/editions/tw5.com/tiddlers/system/GoogleAnalyticsAccount.tid new file mode 100644 index 000000000..1e0f77e7c --- /dev/null +++ b/editions/tw5.com/tiddlers/system/GoogleAnalyticsAccount.tid @@ -0,0 +1,3 @@ +title: $:/GoogleAnalyticsAccount + +UA-32839735-1 \ No newline at end of file diff --git a/editions/tw5.com/tiddlers/system/GoogleAnalyticsDomain.tid b/editions/tw5.com/tiddlers/system/GoogleAnalyticsDomain.tid new file mode 100644 index 000000000..ee2e3f723 --- /dev/null +++ b/editions/tw5.com/tiddlers/system/GoogleAnalyticsDomain.tid @@ -0,0 +1,3 @@ +title: $:/GoogleAnalyticsDomain + +tiddlywiki.com \ No newline at end of file diff --git a/editions/tw5.com/tiddlers/system/analytics.tid b/editions/tw5.com/tiddlers/system/analytics.tid deleted file mode 100644 index 93259def4..000000000 --- a/editions/tw5.com/tiddlers/system/analytics.tid +++ /dev/null @@ -1,14 +0,0 @@ -title: $:/wiki/analytics -type: application/javascript -library: yes - - var _gaq = _gaq || []; - _gaq.push(['_setAccount', 'UA-32839735-1']); - _gaq.push(['_setDomainName', 'tiddlywiki.com']); - _gaq.push(['_trackPageview']); - - (function() { - var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; - ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; - var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); - })(); diff --git a/editions/tw5.com/tiddlywiki.info b/editions/tw5.com/tiddlywiki.info index 177b5dad6..00c423503 100644 --- a/editions/tw5.com/tiddlywiki.info +++ b/editions/tw5.com/tiddlywiki.info @@ -1,6 +1,7 @@ { "plugins": [ "tiddlywiki/fullscreen", + "tiddlywiki/googleanalytics", "tiddlywiki/github-fork-ribbon" ], "themes": [ diff --git a/plugins/tiddlywiki/googleanalytics/googleanalytics.js b/plugins/tiddlywiki/googleanalytics/googleanalytics.js new file mode 100644 index 000000000..477d61d2f --- /dev/null +++ b/plugins/tiddlywiki/googleanalytics/googleanalytics.js @@ -0,0 +1,32 @@ +/*\ +title: $:/plugins/tiddlywiki/googleanalytics/googleanalytics.js +type: application/javascript +module-type: startup + +Runs Google Analytics with the account number in the tiddler `$:/GoogleAnalyticsAccount` and the domain name in `$:/GoogleAnalyticsDomain` + +\*/ +(function(){ + +/*jslint node: true, browser: true */ +/*global $tw: false */ +"use strict"; + +var GOOGLE_ANALYTICS_ACCOUNT = "$:/GoogleAnalyticsAccount", + GOOGLE_ANALYTICS_DOMAIN = "$:/GoogleAnalyticsDomain"; + +exports.startup = function() { + if($tw.browser) { + window._gaq = window._gaq || []; + _gaq.push(["_setAccount", $tw.wiki.getTiddlerText(GOOGLE_ANALYTICS_ACCOUNT)]); + _gaq.push(["_setDomainName", $tw.wiki.getTiddlerText(GOOGLE_ANALYTICS_DOMAIN)]); + _gaq.push(["_trackPageview"]); + var ga = document.createElement("script"); + ga.type = "text/javascript"; + ga.async = true; + ga.src = ("https:" == document.location.protocol ? "https://ssl" : "http://www") + ".google-analytics.com/ga.js"; + document.body.appendChild(ga); + } +}; + +})(); diff --git a/plugins/tiddlywiki/googleanalytics/plugin.info b/plugins/tiddlywiki/googleanalytics/plugin.info new file mode 100644 index 000000000..01bf77fd1 --- /dev/null +++ b/plugins/tiddlywiki/googleanalytics/plugin.info @@ -0,0 +1,6 @@ +{ + "title": "$:/plugins/tiddlywiki/googleanalytics", + "description": "Google Analytics plugin for TiddlyWiki5", + "author": "JeremyRuston", + "core-version": ">=5.0.0" +}