Created
January 15, 2013 11:57
-
-
Save nfreear/4538134 to your computer and use it in GitHub Desktop.
OOcharts / Google Analytics Javascript
This file contains hidden or 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> <title>*OOcharts / Google Analytics</title> | |
| <style> | |
| body{ font:1em sans-serif; background:#fafafa; margin:1em 2em; } | |
| div,p{ margin:1em 0; } | |
| </style> | |
| <!--<script src="http://oocharts.org/release/current/oocharts.js"></script>--> | |
| <script src="toer/oocharts_2.1/oocharts.js"></script> | |
| <script> | |
| oo.setOOId("3a..3b"); // 32 character hash. | |
| oo.load(doCharts); | |
| function doCharts(){ | |
| var profile_id = "1234567" //a34064304w62449462pXXXXXX -- After the "p" (UA-34064304-5) | |
| , sda_start = "2012-12-01" | |
| , date_RE = "^201\\d-[01]\\d-[0-3]\\d$" | |
| , re = new RegExp(date_RE) | |
| , date_start = new Date("2012-12-01") //("12/1/2012") | |
| , date_end = new Date("2012-12-30") //("12/30/2012") | |
| , date_today = new Date() | |
| ; | |
| console.log(re, re.exec(sda_start)); | |
| $('#da-start').html(date_start.toDateString()); | |
| $('#da-end').html(date_end.toDateString()); | |
| //Now I can start drawing charts. | |
| var mv = new oo.Metric(profile_id, date_start, date_end); | |
| mv.setMetric('ga:pageviews'); | |
| mv.draw('met-h1'); | |
| // CHART. | |
| var tl = new oo.Timeline(profile_id, date_start, date_end); | |
| tl.addMetric('ga:visitors', 'Visits'); | |
| tl.addMetric('ga:newVisits', 'New Visits'); | |
| tl.setOption('title', 'Visits Chart'); | |
| tl.setOption('colors', ['blue', 'gray', '#0072c6']); | |
| tl.draw("timeline-div"); | |
| // Events table. | |
| var te = new oo.Table(profile_id, date_start, date_end); | |
| /* | |
| t.addMetric('ga:visitors', 'Visits'); | |
| t.addMetric('ga:bounces', 'Bounces'); | |
| t.addDimension('ga:country', 'Country'); | |
| t.addDimension('ga:city', 'City'); | |
| */ | |
| te.addDimension("ga:eventAction", "Event Action"); | |
| te.addDimension("ga:eventLabel", "Event Label"); | |
| te.addMetric("ga:eventValue", "Event Value (text length/ chars.)"); | |
| te.addMetric("ga:totalEvents", "Total Events"); | |
| te.draw('events-table'); | |
| // Hostnames table. | |
| var th = new oo.Table(profile_id, date_start, date_end); | |
| th.addDimension("ga:hostname", "Host name"); | |
| //th.addDimension("ga:page", "Page"); | |
| th.addDimension("ga:pageTitle", "Page Title"); | |
| th.addMetric("ga:pageviews", "Page views"); | |
| th.draw('hostnames-table'); | |
| /* | |
| // Service provider table. | |
| var ts = new oo.Table(profile_id, date_start, date_end); | |
| ts.addDimension("ga:pageTitle", "Page Title"); | |
| //th.addDimension("ga:page", "Page"); | |
| ts.addDimension("ga:serviceProvider", "Service Provider"); | |
| ts.addMetric("ga:pageviews", "Page views"); | |
| ts.draw('sp-table'); | |
| */ | |
| } | |
| </script> | |
| <p><span id=da-start></span> - <span id=da-end></span></p> | |
| <div id="visits_chart"></div> | |
| <h1 id="met-h1"></h1> | |
| <h3>Page Views</h3> | |
| <h3 id=timeline>Timeline</h3> | |
| <p id=timeline-div></p> | |
| <h3 id=events>Events</h3> | |
| <div id=events-table></div> | |
| <h3 id=sources>Host names (source)</h3> | |
| <div id=hostnames-table></div> | |
| <h3 id=sp>Service Provider (client inst.)</h3> | |
| <div id=sp-table></div> | |
| <pre> | |
| NDF, 15 Jan 2013 | |
| * http://webapps.stackexchange.com/questions/7184/pull-in-google-analytics-charts-onto-my-site | |
| * http://oocharts.org/Guide/P?page=DrawingCharts2_1 | |
| * http://productforums.google.com/forum/#!topic/analytics/dRuAr1K4waI | |
| * http://www.embeddedanalytics.com/embedded-analytics-sample-reports.html | |
| * https://chart.googleapis.com/chart?cht=p&chs=150x150&chco=058dc7&chd=e%3A.. | |
| * https://www.google.com/analytics/web/?hl=en&pli=1#dashboard/default/a34064304w62449462p64014343/%3F_u.date00%3D20121202%26_u.date01%3D20121231/ | |
| <!-- | |
| https://accounts.google.com/o/oauth2/auth?scope=https://www.googleapis.com/auth/analytics.readonly+https://www.googleapis.com/auth/userinfo.profile+https://www.googleapis.com/auth/userinfo.email&redirect_uri=https://oocharts.org/home/processprofile&response_type=code&client_id=1099195286948.apps.googleusercontent.com&access_type=offline&approval_prompt=force | |
| --> | |
| <script> | |
| /* | |
| oo.setPackage('corechart'); | |
| oo.load(drawCharts); | |
| function drawCharts() { | |
| var end_date = new Date(); | |
| var start_date = new Date(); | |
| start_date.setDate(end_date.getDate() - 30); | |
| var c = new oochart("ooid", "aid", start_date, end_date, "line"); | |
| c.setMetric('ga:visitors', 'Visits', 'number'); | |
| c.setDimension('ga:date', 'Date', 'date'); | |
| c.load(function(data){ | |
| for (var i = 0; i < data.length; i++) { data[i][0] = oo.utility.parseAnalyticsDate(data[i][0]); } | |
| c.draw("visits_chart", data); | |
| }); | |
| }*/ | |
| </script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment