This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-03-14
Channels
- # announcements (3)
- # babashka-sci-dev (22)
- # beginners (6)
- # calva (36)
- # cljsrn (1)
- # clojure (59)
- # clojure-europe (31)
- # clojure-france (3)
- # clojure-gamedev (1)
- # clojure-nl (1)
- # clojure-norway (1)
- # clojure-uk (4)
- # clojurescript (6)
- # conjure (1)
- # cursive (11)
- # data-oriented-programming (1)
- # datahike (2)
- # docker (8)
- # duct (4)
- # emacs (1)
- # figwheel-main (5)
- # kaocha (1)
- # leiningen (8)
- # lsp (64)
- # malli (10)
- # membrane (5)
- # nrepl (11)
- # off-topic (5)
- # portal (6)
- # quil (9)
- # reagent (62)
- # reitit (15)
- # releases (3)
- # ring-swagger (2)
- # shadow-cljs (36)
- # specter (2)
- # tools-deps (21)
When doing pageView analytics logging it seems that the router is a good place to do it. It's not fully clear to me how to do it with reitit, though. Anyone has some tips to throw my way? 🙏 Edit: This is frontend reitit.
My first idea would be to add a controller to appropriate place up in the route tree :thinking_face:
Thanks. I tried with a controller first, but I could only make it log on initial page load. Using the navigate fn worked fine!
Just checked and in a real project I’ve actually done it as in the second idea. 😄
More particularly: on-navigate-fn
dispatches a re-frame event :navigated
that causes an effect that reports the page view
Just curious, from the standpoint of how often it fires, what is the practical difference between infiltrating the on-navigate-fn
and using controllers? Don’t they both fire essentially once per page? This is mostly a followup question for @U0ETXRFEW who said that, using controllers, “I could only make it log on initial page load” but I can’t see how that would be different using on-navigate-fn
which it would seem would also only fire once. (At least, with navigate
you only have to write your logic in one place, instead of peppering all your routes with controllers, but I’m really just wanting to understand if this makes any difference with the once-per-page timing.)
It seems like “upper” controllers in nested route trees are applied only once when you enter that “branch” in the routing tree. And this is by design
So my intuitive mental model was just wrong. I think I compared them with middleware
@UTFAPNRPT when I tried it, I did add the controller to all routes. But I couldn't get them to fire more than once, each. There is some semantic around a controller being started that I don't grasp. The on-navigate-fn is called each time a route is entered.