CenterForTheBuiltEnvironment / clima

The CBE Clima Tool is a web-based application built to support the need of architects and engineers interested in climate-adapted design. It allows users to analyze the climate data of more than 27,500 locations worldwide using the data contained in EPW files.
https://clima.cbe.berkeley.edu
MIT License
60 stars 18 forks source link

Look to implement page on-event tracking for google analytics to provide customer insights for Clima sub-pages #151

Open danielh7-cs9 opened 1 year ago

danielh7-cs9 commented 1 year ago

Is your feature request related to a problem? Please describe. No relation to a problem, feature enhancement to allow greater user insights into clima pages used.

Describe the solution you'd like When Clima sub-page is loaded, create event to google analytics

danielh7-cs9 commented 1 year ago

There a couple of ways to do this, but based on my research so far we may need to create additional GTMs and have the js called for certain functions.e.g when user clicks on tab.

Some initial research so far - https://community.plotly.com/t/using-google-analytics-with-dash-app/62347

danielh7-cs9 commented 1 year ago

I've managed to get tracking on each of the clima subpages on my test clima by using Google tag manager.

For each GTM tag, there is an 'on-click' trigger which matches the html click text for each tab. Example below.

image

Each trigger is assigned to a specific GA4 GTM event tag.

image

As users view each tab, each tag is fired and reported back into GA4 dashboards. See below.

image

danielh7-cs9 commented 1 year ago

Hey @FedericoTartarini, please see above for what I've implemented in my non-prod clima. I am able to gather tracking of each clima tabs/pages using triggers and mapping them to GTM events. Let me know if you think/want this implemented in production Clima.

FedericoTartarini commented 1 year ago

It looks great, you can show me this during our next meeting

danielh7-cs9 commented 1 year ago

Hey @FedericoTartarini, I think I found a more elegant way of doing this with GTM with pulling from the datalayer directly.

I created a trigger to track click and fire when the class = "jsx-4020002479".

image

Note - my original plan was to match using CCS selector but I've tried many ways to match the code including Regex and it just wont fire. image

Instead of an individual GTM tag per tab (in red below), we create one and configure the event parameters to return the click value from the datalayer {{Click Text}} image

image

This means if you were to add new tabs to Clima, you wouldn't need to setup a new tag (assuming the trigger conditions the same).

Below are the event counts pushed into GA4.

image

There only cons I do not like with the above is:

  1. At the moment I am matching using a class which seems to be generated from React. I'll see if I am able to use the CCS Selector correctly. image
  2. It is tracking the Select Weather tab but I don't think it is that much of a concern
danielh7-cs9 commented 1 year ago

Trigger conditions using the Click element with CCS Selector is now working. The tag is firing with a conditional match on div id "tabs" nested elements using #tabs *

image

image

This will be the best approach for condition matching as the div id is defined statically in layout.py. image

t-kramer commented 5 months ago

@FedericoTartarini It would be valuable to get this up and running asap. I'll look into this.

FedericoTartarini commented 5 months ago

@t-kramer to implement this properly we need to change the code of clima and make sure that when a person clicks on a tab then the URL changes. To do so you will need to follow this guide https://dash.plotly.com/urls