Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[EAE-117] Add IDs to code for enhanced GA4 tracking #32

Open
wants to merge 3 commits into
base: trunk
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/a.js
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,11 @@ function drawer_init() {
this.classList.contains('active') ? null :
this.getAttribute('for'),
);
gtag('event', 'button_click', {
'event_category': 'Option',
'event_label': 'User selects an option from the left panel',
'value': this.getAttribute('description')
});
};

a.onmouseenter = function() {
Expand Down
6 changes: 6 additions & 0 deletions src/controls.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,12 @@ function toggle_switch(init, callback) {

let status = init || false;

if (status) gtag('event', 'checkbox_checked', {
'event_category': 'Layer',
'event_label': 'User adds a layer to the map',
'value': init.id
});

const active = getComputedStyle(document.body).getPropertyValue('--the-yellow');

svg
Expand Down
14 changes: 13 additions & 1 deletion src/indexes.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ function radio(init, callback) {
.attr('cy', (size/2));

function change(s,i) {
gtag('event', 'select_option', {
'event_category': 'Option',
'event_label': 'User selects an index option',
'value': i.name
});
center
.style('fill', (s ? active : 'white'))
.style('stroke', (s ? active : 'white'));
Expand Down Expand Up @@ -140,7 +145,14 @@ export function init() {
cos.append(ce('option', EAE['indexes'][i]['name'], { "value": i }));

cos.value = U.output;
cos.onchange = x => { O.index = x.target.value; };
cos.onchange = x => {
O.index = x.target.value;
gtag('event', 'select_option', {
'event_category': 'Option',
'event_label': 'User selects an analysis option',
'value': x.target.value
});
};

const toolbox = qs('#index-layer-toolbox');
const tools = {
Expand Down
5 changes: 5 additions & 0 deletions src/s.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,11 @@ export function init() {
for (let co of geographies) {
const d = ce('div', ce('h2', co.name, { "class": 'country-name' }), { "class": 'country-item', "ripple": "" });
d.onclick = async _ => {
gtag('event', 'button_click', {
'event_category': 'Country',
'event_label': 'User selects a country',
'value': c.id
});
preload_boundaries(co.id);
setTimeout(_ => geography(co), 350);
};
Expand Down
14 changes: 14 additions & 0 deletions src/summary.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ async function summary() {
ce('div', "High"),
);

GTAG_EVENT_LABEL = 'User selects REPORT button and then selects an option to export the data'

SUMMARY = {};

const scale = ce('div');
Expand Down Expand Up @@ -136,6 +138,12 @@ async function summary() {
graphs_tab.classList.toggle('hidden');
tables_tab.classList.toggle('hidden');

gtag('event', 'button_click', {
'event_category': 'Option',
'event_label': GTAG_EVENT_LABEL,
'value': "Summary Graphs"
});

this.innerText = ss ? "Summary Table" : "Summary Graphs";
};

Expand All @@ -148,6 +156,12 @@ async function summary() {
return;
}

gtag('event', 'button_click', {
'event_category': 'Option',
'event_label': GTAG_EVENT_LABEL,
'value': "Export Presentation"
});

loading(true);

await delay(0.1);
Expand Down
1 change: 1 addition & 0 deletions views/a.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
<link href="./main.css" rel="stylesheet" />

<script>document.title = EAE['settings'].title;</script>
{{> views/google-analytics }}
</head>

<body>
Expand Down
9 changes: 9 additions & 0 deletions views/google-analytics.mustache
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<!-- Google tag (gtag.js) -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-JVSX1WP1DC"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());

gtag('config', 'G-JVSX1WP1DC');
</script>
1 change: 1 addition & 0 deletions views/m.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
<link href="./main.css" rel="stylesheet" />

<script>document.title = EAE['settings'].title;</script>
{{> views/google-analytics }}
</head>

<body>
Expand Down
1 change: 1 addition & 0 deletions views/s.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
<link href="./main.css" rel="stylesheet" />

<script>document.title = EAE['settings'].title;</script>
{{> views/google-analytics }}
</head>

<body>
Expand Down