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

Add page_view model #1985

Merged
merged 4 commits into from
Mar 7, 2019
Merged

Add page_view model #1985

merged 4 commits into from
Mar 7, 2019

Conversation

benhalpern
Copy link
Contributor

What type of PR is this? (check all applicable)

  • Refactor
  • Feature
  • Bug Fix
  • Documentation Update

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.

@pr-triage pr-triage bot added the PR: unreviewed bot applied label for PR's with no review label Mar 5, 2019

// page view
if (ArticleElement && tokenMeta && !isBot) {
var randomNumber = Math.floor(Math.random() * 10); // 1 in 10; Only track 1 in 10 impressions
Copy link
Contributor

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?

Copy link
Contributor

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.

Copy link
Contributor Author

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) {
Copy link
Contributor

@lightalloy lightalloy Mar 6, 2019

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.

@benhalpern benhalpern merged commit 825aa9b into master Mar 7, 2019
@pr-triage pr-triage bot added PR: merged bot applied label for PR's that are merged and removed PR: unreviewed bot applied label for PR's with no review labels Mar 7, 2019
@maestromac maestromac deleted the ben/add-pageviews-for-articles branch March 7, 2019 20:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PR: merged bot applied label for PR's that are merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants