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

Update GA tracking and a location hash in the URL #13362

Merged
merged 3 commits into from
Nov 30, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
37 changes: 30 additions & 7 deletions static/js/src/navigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,22 @@ function handleDropdownClick(clickedDropdown) {
setTabindex(clickedDropdown.querySelector("ul.p-navigation__dropdown"));
}

function updateUrlHash(id, open) {
if (id !== null && id !== undefined && open) {
Copy link
Contributor

@carkod carkod Nov 29, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it not work with ?

if (id && open) {

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did this as I wanted to allow the url hash to be the other falsey values, but I don't think it is actually needed. So will go with your way.

window.history.pushState(
null,
document.title,
window.location.pathname + window.location.search + `#${id}`
);
} else {
window.history.pushState(
null,
document.title,
window.location.pathname + window.location.search
);
}
}

function goBackOneLevel(e, backButton) {
e.preventDefault();
const target = backButton.parentNode.parentNode;
Expand Down Expand Up @@ -161,6 +177,13 @@ function updateNavMenu(dropdown, show) {
);
let isAccountDropdown = dropdown.classList.contains("js-account");

if (dropdownContent) {
updateUrlHash(dropdown.id, show);
}

// This is needed as the onhover/onfocus effect does not work with touch screens,
// but will trigger calling the navigation contents. We then need to manually
// open the dropdown.
function handleMutation(mutationsList, observer) {
mutationsList.forEach((mutation) => {
if (mutation.type === "childList") {
Expand Down Expand Up @@ -350,7 +373,6 @@ function closeNav() {
});
closeMobileDropdown();
closeDesktopDropdown();

document.removeEventListener("keyup", keyPressHandler);
}

Expand Down Expand Up @@ -388,6 +410,7 @@ function closeMobileDropdown() {
function closeAll() {
closeSearch();
closeNav();
updateUrlHash();
setTabindex(mainList);
}

Expand Down Expand Up @@ -544,13 +567,13 @@ if (accountContainer) {

var origin = window.location.href;

addGANavEvents("#canonical-global-nav", "www.ubuntu.com-nav-global");
addGANavEvents("#all-canonical-link", "www.ubuntu.com-nav-global");
addGANavEvents("#canonical-login", "www.ubuntu.com-nav-0-login");
addGANavEvents("#enterprise-content", "www.ubuntu.com-nav-1-enterprise");
addGANavEvents("#developer-content", "www.ubuntu.com-nav-1-developer");
addGANavEvents("#community-content", "www.ubuntu.com-nav-1-community");
addGANavEvents("#get-ubuntun-content", "www.ubuntu.com-nav-1-get-ubuntu");
addGANavEvents(".p-navigation--secondary", "www.ubuntu.com-nav-2");
addGANavEvents("#use-case", "www.ubuntu.com-nav-1-use-case");
addGANavEvents("#support", "www.ubuntu.com-nav-1-support");
addGANavEvents("#community", "www.ubuntu.com-nav-1-community");
addGANavEvents("#get-ubuntu", "www.ubuntu.com-nav-1-get-ubuntu");
addGANavEvents(".p-navigation.is-secondary", "www.ubuntu.com-nav-2");
addGANavEvents(".p-contextual-footer", "www.ubuntu.com-footer-contextual");
addGANavEvents(".p-footer__nav", "www.ubuntu.com-nav-footer-0");
addGANavEvents(".p-footer--secondary", "www.ubuntu.com-nav-footer-1");
Expand Down
1 change: 0 additions & 1 deletion webapp/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@
subscription_centre,
thank_you,
unlisted_engage_page,
build_engage_pages_sitemap,
navigation_nojs,
)

Expand Down
Loading