coleslaw/plugins/analytics.lisp
Brit Butler e44d0bde9e Make add-injection support more complex injections. Thanks @PuercoPop.
In short, an injection is now a FUNCTION that takes a
document and returns either a STRING to insert in the
page (possibly with data from the document) or NIL.
2014-09-22 14:31:08 -04:00

25 lines
785 B
Common Lisp

(defpackage :coleslaw-analytics
(:use :cl)
(:export #:enable)
(:import-from :coleslaw #:add-injection))
(in-package :coleslaw-analytics)
(defvar *analytics-js*
"<script type=\"text/javascript\">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', '~a']);
_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);
})();
</script>")
(defun enable (&key tracking-code)
(let ((snippet (format nil *analytics-js* tracking-code)))
(add-injection (constantly snippet) :head)))