Using Angular and Google Analytics

By default, Angular does not work very well with Google Analytics. It will only announce a page-view event when refreshing the page. This makes the router in Angular somewhat useless. Luckily, there is an npm package called angular-gtag that hooks into the root app component of your Angular project and sends views upon router navigation. However, I found that the README had a few implicit steps that I needed to do some searching for....

April 18, 2020 · 2 min · Charles M. Knox

How to Fix Angular Not Scrolling to Top for Routerlinks

By default, when using Angular routerLink tags in your HTML, the behavior users will experience when clicking these links is that the browser keeps the current scrollbar positions, before and after clicking. There are cases where this is undesirable, such as when using an Angular router to route URLs (such as /home or /articles ) to Angular components. To fix this, add in your app-routing.module.ts file the following into the @NgModule imports:...

April 17, 2020 · 1 min · Charles M. Knox

Every Outbound Link Leaks Privacy

The title is a bit of an exaggeration, but it’s partly true if you don’t use the correct properties in your HTML elements. In HTML, you should be using rel="noopener noreferrer" along with target="_blank" in your <a> tags - if not, you run major security risks. This GitHub Pages site shows you how: https://apal21.github.io/target-blank/ Many linters will catch this if it’s not set, so make sure that you’re using a linter when you write your code....

April 17, 2020 · 1 min · Charles M. Knox