Last active
January 10, 2017 20:09
-
-
Save bobdanilo/29a5794d3bd3b68ce8face9c57e9d80c to your computer and use it in GitHub Desktop.
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<title>Brasil de Fato | Mais acessadas do dia</title> | |
<meta name="google-signin-client_id" content=> | |
<meta name="google-signin-scope" content="https://www.googleapis.com/auth/analytics"> | |
<link rel="stylesheet" type="text/css" href="//fonts.googleapis.com/css?family=Merriweather" /> | |
<link rel="stylesheet" type="text/css" href="//fonts.googleapis.com/css?family=Merriweather+Sans" /> | |
<style> | |
h1 { | |
text-align: center; | |
font: 700 2rem/1.3 Merriweather,"Times New Roman"; | |
color: #8c191f; | |
} | |
th { | |
padding-bottom: 10px; | |
font: 700 1.1rem "Merriweather Sans", serif ; | |
color: #1A1A1A; | |
} | |
td { | |
font: 400 0.8rem/1.6 Merriweather, "Times New Roman"; | |
} | |
</style> | |
</head> | |
<body> | |
<h1>Brasil de Fato | Mais acessadas do dia</h1> | |
<p> | |
<!-- The Sign-in button. This will run `queryReports()` on success. --> | |
<div class="g-signin2" data-onsuccess="queryReports"></div> | |
</p> | |
<!-- The API response will be printed here. --> | |
<table style="width: 80%; margin: auto; text-align:left;" id="data_results"> | |
<thead> | |
<tr> | |
<th>Página</th> | |
<th>Views</th> | |
</tr> | |
</thead> | |
</table> | |
<script> | |
// Replace with your view ID. | |
var VIEW_ID = 'ga:111717385'; | |
// Query the API and print the results to the page. | |
function queryReports() { | |
gapi.client.request({ | |
path: '/v4/reports:batchGet', | |
root: 'https://analyticsreporting.googleapis.com/', | |
method: 'POST', | |
body: { | |
reportRequests: [ | |
{ | |
viewId: VIEW_ID, | |
dateRanges: [ | |
{ | |
startDate: 'today', | |
endDate: 'today' | |
} | |
], | |
metrics: [ | |
{expression: "ga:pageviews"} | |
], | |
dimensions: [ | |
{"name": "ga:pagePath"} | |
], | |
orderBys: | |
[ | |
{fieldName: "ga:pageviews", "sortOrder": "DESCENDING"} | |
], | |
pageSize: "20", | |
hideTotals: "true", | |
hideValueRanges: "true" | |
} | |
] | |
} | |
}).then(displayResults, console.error.bind(console)); | |
} | |
function displayResults(response) { | |
var results = response.result.reports[0].data.rows; | |
var table = document.getElementById("data_results"); | |
var count = 1; | |
for (i = 0; i < results.length; i++) { | |
var row = table.insertRow(count); | |
var cell1 = row.insertCell(0); | |
var cell2 = row.insertCell(1); | |
url = results[i].dimensions[0]; | |
view = results[i].metrics[0].values[0]; | |
//cell1.innerHTML = "<style='400 0.8rem/1.6 Merriweather'>" + url + "</style>"; | |
cell1.innerHTML = count + ". " + url; | |
cell2.innerHTML = view ; | |
count++; | |
} | |
} | |
</script> | |
<!-- Load the JavaScript API client and Sign-in library. --> | |
<script src="https://apis.google.com/js/client:platform.js"></script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment