https://github.com/whatacold/google-analytics
A ClojureScript library to collect user events to Google Analytics.
https://github.com/whatacold/google-analytics
Last synced: about 2 months ago
JSON representation
A ClojureScript library to collect user events to Google Analytics.
- Host: GitHub
- URL: https://github.com/whatacold/google-analytics
- Owner: whatacold
- License: other
- Created: 2025-03-21T16:23:19.000Z (about 2 months ago)
- Default Branch: master
- Last Pushed: 2025-03-21T17:19:53.000Z (about 2 months ago)
- Last Synced: 2025-03-21T18:27:56.637Z (about 2 months ago)
- Language: Clojure
- Homepage:
- Size: 10.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.org
- License: LICENSE
Awesome Lists containing this project
README
A ClojureScript library for collecting events for Google Analytics.
*The best time to integrate an analytics service was when you shipped, the next best time is NOW.*
* Usage
1. Add the dependency to your project:
- Leiningen/Boot =[org.clojars.kenhuang/google-analytics "0.1.0-SNAPSHOT"]=
- Clojure CLI/deps.edn =org.clojars.kenhuang/google-analytics {:mvn/version "0.1.0-SNAPSHOT"}=Clojars page: https://clojars.org/org.clojars.kenhuang/google-analytics
#+BEGIN_EXPORT html
![]()
#+END_EXPORT2. Based on where you are about to use it, you can =require= different namespaces.
** Using It in a Web App
Note: I haven't managed to do below JS in ClojureScript yet, so we need to include this in HTML at the moment (remember to replace the measurement id =G-YYYYYYYYYY= with yours):
#+begin_src html
window.dataLayer = window.dataLayer || [];
function gtag(){ dataLayer.push(arguments); }
gtag('js', new Date());
gtag('config', 'G-YYYYYYYYYY');
#+end_src
Then collect custom events in CLJS:
#+begin_src clojure
(ns demo
(:require [google-analytics.web :as ga]))(ga/collect-event "event_name" {:param1 1
:param2 "interesting"})
#+end_src
** Using It in a Chrome Extension
#+begin_src clojure
(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"})
#+end_srcMore info on Google:
[[https://developers.google.com/analytics/devguides/collection/protocol/ga4/sending-events][Send Measurement Protocol events to Google Analytics | developers.google.com]]
* LicenseCopyright © 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.