forked from HyperCable/hypercable
-
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.
Merge pull request HyperCable#22 from HyperCable/traffic_campaign
add traffic campaign page
- Loading branch information
Showing
13 changed files
with
126 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// Place all the styles related to the traffic_campaigns controller here. | ||
// They will automatically be included in application.css. | ||
// You can use Sass (SCSS) here: https://sass-lang.com/ |
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,3 @@ | ||
// Place all the styles related to the traffic_sources controller here. | ||
// They will automatically be included in application.css. | ||
// You can use Sass (SCSS) here: https://sass-lang.com/ |
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,17 @@ | ||
# frozen_string_literal: true | ||
|
||
class TrafficCampaignsController < ApplicationController | ||
layout "detail" | ||
|
||
def index | ||
@site = current_user.sites.find_by!(uuid: params[:site_id]) | ||
|
||
base = QueryBuilder.call(Hyper::Event, @site, params).result | ||
current_scope = QueryBuilder.call(Hyper::Event, @site, period: "realtime").result | ||
@current_visitors_count = current_scope.distinct.count(:client_id) | ||
@top_traffic_campaigns = base | ||
.where(event_name: "page_view") | ||
.select("traffic_campaign, count(distinct client_id) as visitors_count, count(*) as count, count(distinct session_id) as sessions_count") | ||
.group("site_id, traffic_campaign").order("2 desc").limit(100) | ||
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,17 @@ | ||
# frozen_string_literal: true | ||
|
||
class TrafficSourcesController < ApplicationController | ||
layout "detail" | ||
|
||
def index | ||
@site = current_user.sites.find_by!(uuid: params[:site_id]) | ||
|
||
base = QueryBuilder.call(Hyper::Event, @site, params).result | ||
current_scope = QueryBuilder.call(Hyper::Event, @site, period: "realtime").result | ||
@current_visitors_count = current_scope.distinct.count(:client_id) | ||
@top_traffic_sources = base | ||
.where(event_name: "page_view") | ||
.select("traffic_source, count(distinct client_id) as visitors_count, count(*) as count, count(distinct session_id) as sessions_count") | ||
.group("site_id, traffic_source").order("2 desc").limit(100) | ||
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,4 @@ | ||
# frozen_string_literal: true | ||
|
||
module TrafficCampaignsHelper | ||
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,4 @@ | ||
# frozen_string_literal: true | ||
|
||
module TrafficSourcesHelper | ||
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
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,28 @@ | ||
<div class="dark:bg-gray-800"> | ||
<h1 class="text-xl font-bold dark:text-gray-100">Top Traffic Campaign</h1> | ||
<div class="my-4 border-b border-gray-300"> | ||
|
||
</div> | ||
<main class="modal__content"> | ||
<table class="w-full table-striped table-fixed"> | ||
<thead> | ||
<tr> | ||
<th class="p-2 text-xs tracking-wide font-bold text-gray-500 dark:text-gray-400" align="left">Traffic Campaign</th> | ||
<th class="p-2 w-32 text-xs tracking-wide font-bold text-gray-500 dark:text-gray-400" align="right">Visitors</th> | ||
<th class="p-2 w-32 text-xs tracking-wide font-bold text-gray-500 dark:text-gray-400" align="right">Pageviews</th> | ||
<th class="p-2 w-32 text-xs tracking-wide font-bold text-gray-500 dark:text-gray-400" align="right">Sessions</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
<% @top_traffic_campaigns.each do |agg| %> | ||
<tr class="text-sm dark:text-gray-200"> | ||
<td class="p-2"><%= agg.traffic_campaign %></td> | ||
<td class="p-2 w-32 font-medium" align="right"><%= pretty_num agg.visitors_count %></td> | ||
<td class="p-2 w-32 font-medium" align="right"><%= pretty_num agg.count %></td> | ||
<td class="p-2 w-32 font-medium" align="right"><%= pretty_num agg.sessions_count %></td> | ||
</tr> | ||
<% end %> | ||
</tbody> | ||
</table> | ||
</main> | ||
</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,28 @@ | ||
<div class="dark:bg-gray-800"> | ||
<h1 class="text-xl font-bold dark:text-gray-100">Top Traffic Source</h1> | ||
<div class="my-4 border-b border-gray-300"> | ||
|
||
</div> | ||
<main class="modal__content"> | ||
<table class="w-full table-striped table-fixed"> | ||
<thead> | ||
<tr> | ||
<th class="p-2 text-xs tracking-wide font-bold text-gray-500 dark:text-gray-400" align="left">Traffic Source</th> | ||
<th class="p-2 w-32 text-xs tracking-wide font-bold text-gray-500 dark:text-gray-400" align="right">Visitors</th> | ||
<th class="p-2 w-32 text-xs tracking-wide font-bold text-gray-500 dark:text-gray-400" align="right">Pageviews</th> | ||
<th class="p-2 w-32 text-xs tracking-wide font-bold text-gray-500 dark:text-gray-400" align="right">Sessions</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
<% @top_traffic_sources.each do |agg| %> | ||
<tr class="text-sm dark:text-gray-200"> | ||
<td class="p-2"><%= agg.traffic_source %></td> | ||
<td class="p-2 w-32 font-medium" align="right"><%= pretty_num agg.visitors_count %></td> | ||
<td class="p-2 w-32 font-medium" align="right"><%= pretty_num agg.count %></td> | ||
<td class="p-2 w-32 font-medium" align="right"><%= pretty_num agg.sessions_count %></td> | ||
</tr> | ||
<% end %> | ||
</tbody> | ||
</table> | ||
</main> | ||
</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
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,9 @@ | ||
# frozen_string_literal: true | ||
|
||
require "test_helper" | ||
|
||
class TrafficCampaignsControllerTest < ActionDispatch::IntegrationTest | ||
# test "the truth" do | ||
# assert true | ||
# 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,9 @@ | ||
# frozen_string_literal: true | ||
|
||
require "test_helper" | ||
|
||
class TrafficSourcesControllerTest < ActionDispatch::IntegrationTest | ||
# test "the truth" do | ||
# assert true | ||
# end | ||
end |