nickurban

nickurban

How to track usage of a LiveView app -- Google Analytics?

I’m wondering, perhaps I could track “page loads” in Google Analytics using hooks like on_mount, but mounted seems too limited, and beforeUpdate seems too general (it would fire even if the URL did not change, although perhaps I could check for that?)

Is there some other better way to track usage of a LiveView app?
Thanks!

Most Liked

harmon25

harmon25

This is how I tackled the same issue but with analytics.js.
I think the phx:page-loading-stop event listener is the place to track live redirects/patches.

window.addEventListener("phx:page-loading-stop", (info) => {
  //hides loading bar
  topbar.hide();
  // liveredirects/livepatches tracked as a page view
  if (["redirect", "patch"].includes(info.detail.kind)) {
    window.analytics.page();
  }
});
lukeses

lukeses

As LiveView uses browser’s pushState API, it is possible to use History Change Trigger in Google Tag Manager. Used approach might depend a bit, from which place, you want to control tracking in general. I was able to get an event in Google Analytics, whenever a path changes on LiveView page.

cgarvis

cgarvis

Is there any way to do this without javascript?

Last Post!

Exadra37

Exadra37

You now have a lib to provide Phoenix Analytics from the backend.

I took some notes and wrote also the code from the YoutubeVideo at Phoenix Analytics: open-source view tracking, in your app! - Video Pundits

Where Next?

Popular in Questions Top

nobody
Hi! In PHP: $_SERVER[‘SERVER_ADDR’] - in Elixir? Searched the docs for ip address and the web, no good results. Thanks!
New
vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod – where is this set? Thanks.
New
skosch
To my knowledge, put_in, Map.update etc. all have the one limitation of not automatically creating intermediate keys when needed (for exa...
New
9mm
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New
sen
Hi All, I set a environment variables in dev.exs , like below code. when i start server, how can i set the ${enable} value? thanks. d...
New
jason.o
In the code below, if the create action is not set to accept “extra_key” as an input, it errors out with a message shown above. Is there ...
New

Other popular topics Top

jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod – where is this set? Thanks.
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New
dokuzbir
I want to highlight html closing tags when i click a html tag. That works in .html files but doesnt work for html.eex templates. How can...
New
saif
Hello everyone, Long time lurker first time poster here. I’ve recently begun working on Elixir full-time again! :raised_hands: It’s been...
New
albydarned
Hello all! I am typing this post from my new MacBook Pro with the M1 chip. I’m loving it so far, and will probably use it as my daily dr...
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New

We're in Beta

About us Mission Statement