Analytics for Clojure


The library is open-source and was contributed by the very awesome CircleCI, thanks! You can check it out on GitHub. The clojure library is a wrapper around our Java library.

The clojure library (like our other server side libraries) is built for high-performance, so you can use them in your web server controller code. This library uses an internal queue to make calls non-blocking and fast. It also batches messages and flushes asynchronously to our servers.

Getting Started

If you’re using Maven add this repository definition to your pom.xml:


Then, if you’re using Leiningen:

[circleci/analytics-clj "0.8.0"]

or with Maven


You only need to initialize once at the start of your program. You can then keep using the Analytics singleton anywhere in your code.

(use '[])
(def analytics (initialize "<writeKey>"))

The default initialization settings are production-ready.



We recommend calling identify a single time when the user’s account is first created, and only identifying again later when their traits are change.

Example identify call:

(identify analytics "user-id" {:email ""})

This call is identifying the user by his unique User ID (the one you know him by in your database) and labeling him with an email trait.

The identify call has the following fields:

user-id String The ID for this user in your database.
traits Map, optional A map of traits you know about the user. Things like: email, name or friends.

Find details on the identify method payload in our Spec.


track lets you record the actions your users perform. Every action triggers what we call an “event”, which can also have associated properties.



Example track call:

(track analytics "user-id" "Signed Up" {:plan "trial"})
(track analytics (:id user) "signup" {:company "Acme Inc."} {:context {:language "en-us"}
   :integrations {"AdRoll" false}
   :integration-options {"Amplitude" {:session-id (:id session)}}})

This example track call tells us that your user just triggered the Signed Up event on a “trial” plan.

track event properties can be anything you want to record. In this case, plan type.

The track call has the following fields:

event String The name of the event you’re tracking. We recommend human-readable names like Song Played or Status Updated.
properties Map, optional A map of properties for the event. If the event was Added to Cart, it might have properties like price or product.

Find details on best practices in event naming as well as the track method payload in our Spec.


group lets you associate an identified user user with a group. A group could be a company, organization, account, project or team! It also lets you record custom traits about the group, like industry or number of employees.


(group analytics "1234" "group-5678" {:name "Segment"})

The group call has the following fields:

userId String The ID for this user in your database.
groupId String The ID for this group in your database.
traits Traits, optional A dictionary of traits you know about the group. Things like: name or website.

Find more details about group, including the group payload, in our Spec.


The screen method lets you record whenever a user sees a screen of your mobile app, along with optional extra information about the page being viewed.

You’ll want to record a screen event an event whenever the user opens a screen in your app.

Not all services support screen, so when it’s not supported explicitly, the screen method tracks as an event with the same parameters.

(screen analytics "1234" "Login" {:path "/users/login"})

The screen call has the following fields:

userId String The ID for this user in your database.
name String The webpage name you’re tracking. We recommend human-readable names like Login or Register.
properties Properties, optional A dictionary of properties for the webpage visit. If the event was Login, it might have properties like path or title.



In Mixpanel it’s used to associate an anonymous user with an identified user once they sign up. For Kissmetrics, if your user switches IDs, you can use ‘alias’ to rename the ‘userId’.

Example alias call:

(alias analytics "user-id" "real-id")



If the above methods don’t meet your needs, you can use the builder types directly.

(enqueue analytics (doto (YourMessageType/builder)
 (.userId "user-id")
 (.properties {"company" "Acme Inc."})))


You can set a custom logger on the client using:

(defn logger []
    (print [this level format args]
      (println (str (java.util.Date.) "\t" level "\t" args)))
    (print [this level error format args]
      (println error))))

(def analytics (initialize "<writeKey>" {:log (logger)}))



No events in my debugger

  1. Double check that you’ve set up the library correctly.


No events in my end tools

  1. Double check your credentials for that destination.



This page was last modified: 18 Sep 2020

Get started with Segment

Create free account