loading...

re: Analytics with vanilla JS: page views VIEW POST

TOP OF THREAD FULL DISCUSSION
re: In my (relatively short) experience: It doesn't hurt to have aggregate metrics like time series of sessions, pageviews, geographical distribution ...

Hey thanks for this.

As I mentioned in the first article of the series Motivation I'm going towards analytics that can be integrated directly into product development cycle. What you described definitely fits the bill. Really good point if you don't mind I'll use it :)

On marketing <=> developer relationships I couldn't agree more. Software is useless if nobody's using it and developers are too often way to far from direct customer interaction.

If you ask me. Software development is easy. Selling the product is hard :D

Sure, feel free to use the ideas! Glad I could add something positive to the discussion! Please, keep us posted as you move forward 😉

I couldn't agree more: software is not an obstacle, being able to sell profitably and grow healthy is really hard!

Great. I want to bounce another thought.

Tracking sources of traffic is easy. Proper URL parameters and that's it. But connecting efforts to actions over multiple web page user visits that's a bit harder.

I've come up with a solution that uses localStorage but local storage can disabled. Sure the amount of users with disabled localStorage will be small but still.

Is there maybe a more elegant way to connect multiple separate web page visits to a single user? I'm probably missing something due to my basic knowledge of JS.

I would suggest generating a unique hash for each visitor. Maybe an MD5 hash of multiple values concatenated:

  • User-agent
  • IP address
  • Timestamp
  • Random 9-digit number (extra careful avoiding hash collision)

Store this hash as a cookie in the browser. When the person comes back later, your script can identify it's the same person.

Store the user hash with every interaction (even pageviews). Later, when you're analyzing an action (e.g. "user subscribed to the service"), you can get the user-hash and search every other interaction associated with it in the past.


About tracking the source of traffic, it's not going to be easy anymore. All major browsers are adopting strict "no-referrer" policies now. What this means is:

  1. The person is reading an article in dev.to/author/article-title-here-123
  2. There's a link to your site (zigabrencic.com/), in which the reader clicks
  3. When requesting your site content, the browser will send only "dev.to/" in the Referrer Header, not the entire URL

They're making this switch for privacy and security reasons. It's a good thing, but it will make it a lot more difficult to track sources with precision. Unless we use UTM parameters in the URL, there's no way to know from which page the visitor came.

Hash thats clever 🙂 I was thinking about just some unique user id. Thanks.
————

On URL. Privacy reasons I get and I know that UTMs are more reliable but what are the security issues of referrals?

It's possible for the origin to add user sensitive data in the URL. It's bad practice, but I'd say there's 99.99999% chance that at least a handful of sites is doing that right now.

In that event, the target site can access user data without its consent from the referrer header.

Alright yeah that’s problematic. Never thought of that 🤷‍♂️

Me neither!.. 😊

I was just pissed at Google Analytics recently and thinking about building something better and started researching, your article caught my attention 😄

Haha nice :D

My disagreement with Google Analytics got on this path to yeah. What encouraged me to start building my own analytics were those guys: usefathom.com

Before that I never thought that one could build reliable custom analytics. But apparently two developers did.

code of conduct - report abuse