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

[DO NOT MERGE] Update search dashboard #165

Open
wants to merge 14 commits into
base: main
Choose a base branch
from
Open
21 changes: 21 additions & 0 deletions GA4_handlers/active_users_yesterday.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
require "google/analytics/data/v1beta"

def active_users_yesterday
client = ::Google::Analytics::Data::V1beta::AnalyticsData::Client.new

request = Google::Analytics::Data::V1beta::RunReportRequest.new(
property: "properties/330577055",
date_ranges: [
{ start_date: "yesterday", end_date: "yesterday" }
],
metrics: [
{ name: "activeUsers" }
]
)

response = client.run_report(request)

if response.rows.any?
active_users_yesterday = response.rows[0].metric_values[0].value
end
end
101 changes: 64 additions & 37 deletions public/index.html

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions public/javascripts/govuk-frontend-5.8.0.min.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions public/javascripts/govuk-frontend-5.8.0.min.js.map

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions public/javascripts/manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@
$body.addClass('tall');
}
matrix.traffic.init();
matrix.trafficYesterday.init();
matrix.search.init();
matrix.content.init();
matrix.recentlyPublished.init();
},
};
root.matrix.manager = manager;
Expand Down
15 changes: 8 additions & 7 deletions public/javascripts/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,16 +104,17 @@
},

displayResults: function(){
var term = search.newTerms.pop();
var term = search.newTerms.pop() || search.terms?.pop()?.term
if(term){
console.warn(term)
var updateElement = search.updateElement();
updateElement.prepend('<li class="govuk-body-l">'+$('<div class="govuk-body-l">').text(term).html()+'</li>');
updateElement.prepend('<li class="govuk-body govuk-!-font-size-36 govuk-!-static-margin-bottom-5">'+$('<div class="govuk-body-l">').text(term).html()+'</li>');
updateElement.css('margin-top',-search.$el.find('li').first().outerHeight(true)).animate({'margin-top':0}, function(){
search.$el.find('li:gt(20)').remove();
root.setTimeout(search.displayResults, (search.nextRefresh - Date.now()) / search.newTerms.length);
search.$el.find('li:gt(18)').remove();
root.setTimeout(search.displayResults, 100);
});
} else {
root.setTimeout(search.displayResults, 5e3);
root.setTimeout(search.displayResults, 100);
}
},

Expand All @@ -122,13 +123,13 @@

search.reload();
search.displayResults();
window.setInterval(search.reload, 60e3);
window.setInterval(search.reload, 10e3);
},

reload: function(){
var endpoint = search.endpoint();

search.nextRefresh = Date.now() + 60e3;
search.nextRefresh = 100 + 100;
$.ajax({ dataType: 'json', url: endpoint, success: search.parseResponse });
},

Expand Down
37 changes: 37 additions & 0 deletions public/javascripts/traffic-yesterday.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
(function(){
"use strict"
var root = this,
$ = root.jQuery;
if(typeof root.matrix === 'undefined'){ root.matrix = {} }

var trafficYesterday = {
$el: false,
user_count: 0,

endpoint: function(){
return "/active-users-yesterday";
},

parseResponse: function(data){
console.warn(data)
trafficYesterday.user_count = data
trafficYesterday.displayResults()
},
displayResults: function(){
trafficYesterday.$el.text(root.matrix.numberWithCommas(trafficYesterday.user_count))
},
init: function(){
trafficYesterday.$el = $('#traffic-count-yesterday');

trafficYesterday.reload();
window.setInterval(trafficYesterday.reload, 86400000);
},
reload: function(){
var endpoint = trafficYesterday.endpoint();

$.ajax({ dataType: 'json', url: endpoint, success: trafficYesterday.parseResponse});
}
};

root.matrix.trafficYesterday = trafficYesterday;
}).call(this);
1 change: 1 addition & 0 deletions public/javascripts/traffic.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
},

parseResponse: function(data){
console.warn(data)
traffic.user_count = data.active_users_30_minutes
traffic.displayResults()
},
Expand Down
45 changes: 17 additions & 28 deletions public/stylesheets/govuk-custom-dashboard.css
Original file line number Diff line number Diff line change
@@ -1,40 +1,29 @@
/* Note: `!important` is used to override default gov.uk css styles */


html,body {
background-color: #282D30 !important;
html,
body {
background-color: #0b0c0c !important;
height: 100vh;
}

.dashboard-banner {
border-bottom: 10px solid #0b0c0c;
.dashboard-body--flex {
box-sizing: border-box;
display: flex;
flex-direction: column;
margin: 0;
padding: 30px 50px;
}

.dashboard-banner-inner {
border-bottom: 10px solid #0b0c0c;
margin-left: 20px;
margin-right: 0 !important;
max-width: 100% !important;
.dashboard-body--flex .dashboard-main {
flex-grow: 1;
overflow: hidden;
}

.dashboard-banner-inner {
display: flex;
justify-content: space-between;
.dashboard-logo {
align-items: center;
}
#slack-channel-link {
margin-right: 20px;
font-size: 32px;
}
.govuk-header__logo{
flex: 1;
}

.dashboard-background {
padding: 20px;
background-color: #282D30;
display: flex;
}

.dashboard-number-count {
text-align: left;
font-size: 72px;
.text-wrap-balance {
text-wrap: balance
}
3 changes: 3 additions & 0 deletions public/stylesheets/govuk-frontend-5.8.0.min.css

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions public/stylesheets/govuk-frontend-5.8.0.min.css.map

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions public/stylesheets/govuk-frontend-5.8.0.min.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions public/stylesheets/govuk-frontend-5.8.0.min.js.map

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
require 'dotenv/load'
require "google/analytics/data/v1beta"
require_relative 'GA4_handlers/active_users'
require_relative 'GA4_handlers/active_users_yesterday'
require_relative 'GA4_handlers/popular_content'
require_relative 'GA4_handlers/live_searches'
autoload :Google, 'google-analytics-data-v1beta'
Expand Down Expand Up @@ -51,6 +52,11 @@
active_users
end

get '/active-users-yesterday' do
content_type :json
active_users_yesterday
end

get '/recently-published' do
http = Net::HTTP.new('www.gov.uk', 443)
http.use_ssl = true
Expand Down
Loading