Skip to content

📈A ClojureScript library for collecting custom events to Google Analytics.

License

Notifications You must be signed in to change notification settings

whatacold/google-analytics

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

Usage

  1. Add the dependency to your project: https://img.shields.io/clojars/v/org.clojars.kenhuang/google-analytics.svg
  2. Based on where you are about to use it, you can require different namespaces.

Using It in a Web App

(ns demo
  (:require [google-analytics.web :as ga]))

(ga/init! "G-YYYYYYYYYY")
(ga/collect-event "event_name" {:param1 1
                                :param2 "interesting"})

Using It in a Chrome Extension

(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

Try the Demo

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

License

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.

About

📈A ClojureScript library for collecting custom events to Google Analytics.

Resources

License

Stars

Watchers

Forks