A ClojureScript library for collecting events for Google Analytics.
The best time to integrate an analytics service was before you shipped, the next best time is NOW.
- Add the dependency to your project:
- Based on where you are about to use it, you can
require
different namespaces.
(ns demo
(:require [google-analytics.web :as ga]))
(ga/init! "G-YYYYYYYYYY")
(ga/collect-event "event_name" {:param1 1
:param2 "interesting"})
(ns demo
(:require [google-analytics.browser-ext :as ga]))
;; init it with the measurement id and api secret
;; replace them with yours
(ga/init! "G-YYYYYYYYYY" "***your api-secret***")
;; collect an event
(ga/collect-event "event_name" {:param1 "value1"})
Please note that it requires storage permission to store the client id and the session info.
More info on Google: Send Measurement Protocol events to Google Analytics | developers.google.com
There is a demo project using shadow-cljs under ./demo/
directory, you can play with it after replacing the measurement ids and the api secret:
# install shadow-cljs
npm install --save-dev shadow-cljs
# install react for the web app
npm install "[email protected]" "[email protected]"
# watch both builds for dev
npx shadow-cljs watch :webapp :chrome-ext
Copyright © 2025 Ken Huang
This program and the accompanying materials are made available under the terms of the Eclipse Public License 2.0 which is available at http://www.eclipse.org/legal/epl-2.0.
This Source Code may also be made available under the following Secondary Licenses when the conditions for such availability set forth in the Eclipse Public License, v. 2.0 are satisfied: GNU General Public License as published by the Free Software Foundation, either version 2 of the License, or (at your option) any later version, with the GNU Classpath Exception which is available at https://www.gnu.org/software/classpath/license.html.