0

I'm trying to think of a smart way to roughly measure unique page views of my website.

My first thought was to have a database table recording every hit, but that doesn't get around the issue of the same user constantly refreshing the page.

Instead, I'm wondering if cookies is a reasonable idea (or perhaps a mixture of database records and cookies?).

Something like:

//on page hit

let pageViews = cookies.get('myWebsitePageViews');

//pageViews = '12, 135, 14, 2, 5' <---a string of page IDs

if(pageViews.contains(thisPageID){
    // do not add new entry to cookie string
}
else{
    cookies.add('myWebsitePageViews', pageViews + ', ' +  thisPageID.ToString());
    serverCall.IncrementPageView(thisPageID);       
}

I understand cookies can be deleted or disabled, but generally this would do the job as I'm not looking for strict accuracy. I just need something to prevent the average user from bumping up page views via constant page reloads.

I'm wondering if there's any major issue with this, or any better method that I'm unaware of.

Thanks.

Stuart Aitken
  • 949
  • 1
  • 13
  • 30
  • why not just use google analytics? – Andy Ray Dec 03 '18 at 05:37
  • @AndyRay I wasn't aware it was possible using Analytics. A quick google search tells me there's an Analytics API, which is definitely an interesting possibility, thanks. Ideally I'd prefer something in real-time though, and not tied to an external API. My website is currently set to manually store and increment page views already, so the one problem is how to figure out unique views. – Stuart Aitken Dec 03 '18 at 05:56
  • google analytics is free and gives you a real time view dashboard. you could also just scrape this data from server logs – Andy Ray Dec 03 '18 at 06:08
  • @AndyRay If it's real-time then that's great. I read another comment saying it isn't real-time. I'll look into it anyway, thanks again. – Stuart Aitken Dec 03 '18 at 07:54

0 Answers0