posthog.cljs 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. (ns frontend.modules.instrumentation.posthog
  2. (:require [frontend.config :as config]
  3. [frontend.util :as util]
  4. [frontend.mobile.util :as mobile-util]
  5. [frontend.version :refer [version]]
  6. ["posthog-js" :as posthog]
  7. [cljs-bean.core :as bean]))
  8. (def ^:const token "qUumrWobEk2dKiKt1b32CMEZy8fgNS94rb_Bq4WutPA")
  9. (def ^:const masked "masked")
  10. (defn register []
  11. (posthog/register
  12. (clj->js
  13. {:app_type (let [platform (mobile-util/platform)]
  14. (cond
  15. (util/electron?)
  16. "electron"
  17. platform
  18. platform
  19. :else
  20. "web"))
  21. :app_env (if config/dev? "development" "production")
  22. :app_ver version
  23. :schema_ver 0
  24. ;; hack, did not find ways to hack data on-the-fly with posthog-js
  25. :$current_url masked
  26. :$pathname masked})))
  27. (def config
  28. {:api_host "https://app.posthog.com"
  29. :persistence "localStorage"
  30. :autocapture false
  31. :disable_session_recording true
  32. :mask_all_text true
  33. :mask_all_element_attributes true
  34. :loaded (fn [_] (register))})
  35. (defn init []
  36. (posthog/init token (clj->js config)))
  37. (defn opt-out [opt-out?]
  38. (if opt-out?
  39. (posthog/opt_out_capturing)
  40. (do
  41. (init)
  42. (posthog/opt_in_capturing))))
  43. (defn capture [id data]
  44. (try
  45. (posthog/capture (str id) (bean/->js data))
  46. (catch js/Error e
  47. (js/console.error e)
  48. ;; opt out or network issues
  49. nil)))
  50. (comment
  51. (posthog/debug))