Merge pull request #197 from shukryzablah/update-analytics-plugin

Update google analytics integration: create gtag plugin
This commit is contained in:
Cthulhux 2021-05-26 16:05:23 +02:00 committed by GitHub
commit 891bfd52de
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 24 additions and 1 deletions

View file

@ -19,7 +19,9 @@ The former default deployment method.
**Description**: Provides traffic analysis through
[Google Analytics](http://www.google.com/analytics/).
**Example**: `(analytics :tracking-code "google-provided-unique-id")`
**Example**: `(gtag :tracking-code "google-provided-unique-id")`
**Note**: You can use `(analytics :tracking-code "google-provided-unique-id")` for the legacy integration with Google Analytics.
## Analytics via Piwik

21
plugins/gtag.lisp Normal file
View file

@ -0,0 +1,21 @@
(defpackage :coleslaw-gtag
(:use :cl)
(:export #:enable)
(:import-from :coleslaw #:add-injection))
(in-package :coleslaw-gtag)
(defvar *analytics-js*
"<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src='https://www.googletagmanager.com/gtag/js?id=~a'></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', '~a');
</script>")
(defun enable (&key tracking-code)
(let ((snippet (format nil *analytics-js* tracking-code tracking-code)))
(add-injection (constantly snippet) :head)))