-
Notifications
You must be signed in to change notification settings - Fork 4k
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
Add page_view model #1985
Add page_view model #1985
Conversation
|
||
// page view | ||
if (ArticleElement && tokenMeta && !isBot) { | ||
var randomNumber = Math.floor(Math.random() * 10); // 1 in 10; Only track 1 in 10 impressions |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why don't you want to track all views?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suppose that it's done for optimization, to make fewer requests and db writes. For unauthorized users, only one of each 10 requests will be saved, but the count will be 10 (https://github.com/thepracticaldev/dev.to/pull/1985/files#diff-a71fed5e724b3cd9cce62138dfb4d631R10), so the number of views will remain approximately the same as if every request was tracked.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup, that’s the logic. We can adjust things later, but this should be a bit less resource costly and give us good enough insights.
// page view | ||
if (ArticleElement && tokenMeta && !isBot) { | ||
var randomNumber = Math.floor(Math.random() * 10); // 1 in 10; Only track 1 in 10 impressions | ||
if (!checkUserLoggedIn() && randomNumber != 1) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest transforming this condition to smth like if !(checkUserLoggedIn() || randomNumber == 1)
, in my opinion it's easier to understand.
…to ben/add-pageviews-for-articles
What type of PR is this? (check all applicable)
Description
This feature adds custom tracking of page views from within the app to complement and compare against Google Analytics data. This should make initial reporting faster and more reliable.
This also opens up the opportunity to show users their history.