This is re-frame library, which contains several Effect Handlers for working with Google Analytics.
[district0x.re-frame/google-analytics-fx "1.0.0"]
(ns my.app
(:require [district0x.re-frame.google-analytics-fx])
Add Google Analytics snippet to your page. Don't copy this one, may be outdated
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-XXXXX-Y', 'auto');
</script>
To enable or disable logging use:
(district0x.re-frame.google-analytics-fx/set-enabled! false)
; To Disable while developing:
(district0x.re-frame.google-analytics-fx/set-enabled! (not goog.DEBUG))
Following effect handlers are available. Note, none of parameters is mandatory. fields-object
always goes through clj->js
(reg-event-fx
:some-event
(fn []
{:ga/page-view [url fields-object]}))
(reg-event-fx
:some-event
(fn []
{:ga/event [category action label value fields-object]}))
(reg-event-fx
:some-event
(fn []
{:ga/social [social-network social-action social-target fields-object]}))
(reg-event-fx
:some-event
(fn []
{:ga/screen-view [fields-object]}))
(reg-event-fx
:some-event
(fn []
{:ga/timing [timing-category timing-var timing-value timing-label fields-object]}))
(reg-event-fx
:some-event
(fn []
{:ga/exception [description fatal?]}))
(reg-event-fx
:some-event
(fn []
{:ga/send [fields-object]}))
(reg-event-fx
:some-event
(fn []
{:ga/set [fields-object]}))
(reg-event-fx
:some-event
(fn []
{:ga/create [tracking-id cookie-domain name fields-object]}))