Last Updated: February 25, 2016
·
1.112K
· rarous

Google Analytics tracking in ClojureScript

When you integrate advanced analytics in to your ClojureScript application, you will get into moment when you need to call ga tracking function. You can define all arities, but it is unnecessary work. We can simply translate into JavaScript arguments application.

(defn ga [& more]
  (when js/ga
    (.. (aget js/window "ga")
        (apply nil (clj->js more)))))

First we check, if global ga function is present. To prevent rename of ga function name in advanced mode compilation, we have to array access it (aget) from global object. Then we apply arguments converted to JavaScript Array.