forked from forem/forem
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adjust dashboard analytics to be more reliable (forem#1115)
* Update analytics * Remove analytics file * Remove unused files * Add delete button back in on dashboard
- Loading branch information
1 parent
652ec00
commit c580720
Showing
13 changed files
with
149 additions
and
249 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 0 additions & 32 deletions
32
app/assets/javascripts/initializers/initializeAnalytics.js
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
class ArticleAnalyticsFetcher | ||
def update_analytics(user_id) | ||
articles_to_check = Article.where(user_id: user_id, published: true) | ||
qualified_articles = get_articles_that_qualify(articles_to_check) | ||
return if qualified_articles.none? | ||
fetch_and_update_page_views_and_reaction_counts(qualified_articles, user_id) | ||
end | ||
|
||
def fetch_and_update_page_views_and_reaction_counts(qualified_articles, user_id) | ||
qualified_articles.each_slice(15).to_a.each do |chunk| | ||
pageviews = GoogleAnalytics.new(chunk.pluck(:id), user_id).get_pageviews | ||
page_views_obj = pageviews.to_h | ||
chunk.each do |article| | ||
article.update_columns(previous_positive_reactions_count: article.positive_reactions_count) | ||
next if article.page_views_count > page_views_obj[article.id].to_i | ||
article.update_columns(page_views_count: page_views_obj[article.id].to_i) | ||
end | ||
end | ||
end | ||
|
||
def get_articles_that_qualify(articles_to_check) | ||
qualified_articles = [] | ||
articles_to_check.each do |article| | ||
if should_fetch(article) | ||
qualified_articles << article | ||
end | ||
end | ||
qualified_articles | ||
end | ||
|
||
def should_fetch(article) | ||
article.positive_reactions_count > article.previous_positive_reactions_count | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<% num_views = @articles.sum(&:page_views_count) %> | ||
|
||
<div class="dashboard-analytics-header-wrapper"> | ||
<div class="dashboard-analytics-header"> | ||
<span><%= number_with_delimiter(@articles.sum(&:positive_reactions_count), delimeter: ",") %></span> | ||
<div class="dashboard-analytics-sub-indicator"> | ||
<img src="<%= asset_path "emoji/emoji-one-heart.png" %>" /><img src="<%= asset_path "emoji/emoji-one-unicorn.png" %>" /><img src="<%= asset_path "emoji/emoji-one-bookmark.png" %>" /> | ||
Total Post Reactions | ||
</div> | ||
</div> | ||
<div class="dashboard-analytics-header" id="dashboard-analytics-header"> | ||
<span><%= num_views > 500 ? number_with_delimiter(num_views, delimeter: ",") : "under 500" %></span> | ||
<div class="dashboard-analytics-sub-indicator"> | ||
<img id="dashboard-analytics-image" src="<%= asset_path "emoji/apple-eyes.png" %>" /> | ||
Total Post Views | ||
</div> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<div class="single-article"> | ||
<a href="<%= article.current_state_path %>"><h2><%= article.title %></h2></a> | ||
<div class="dashboard-actions"> | ||
<% if !article.published %> | ||
<span class="pill cta yellow">DRAFT</span> | ||
<% end %> | ||
<a href="<%= article.path %>/edit" class="pill cta green">EDIT</a> | ||
<a href="<%= article.path %>/delete_confirm" data-no-instant class="cta pill black">DELETE</a> | ||
<% if article.published && current_user.can_view_analytics? %> | ||
<span id="pageviews-<%= article.id %>" class="cta pill dashboard-pageviews-indicator" data-analytics-pageviews data-article-id="<%= article.id %>"> | ||
<%= article.page_views_count > 100 ? article.page_views_count : "under 100" %> views // <%= article.positive_reactions_count %> reactions | ||
</span> | ||
<% end %> | ||
</div> | ||
<% if org_admin %> | ||
<%= form_for(article) do |f| %> | ||
<input type="hidden" name="destination" value="/dashboard" /> | ||
AUTHOR: <%= f.select(:user_id, options_for_select(@user.organization.users.map {|x| [x.name, x.id] }, article.user_id )) %> | ||
<%= f.submit "SUBMIT AUTHOR CHANGE", class:"cta pill black" %> | ||
<% end %> | ||
<% end %> | ||
</div> |
Oops, something went wrong.