Skip to content

Instantly share code, notes, and snippets.

@dustinlarimer
Last active August 29, 2015 13:57
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dustinlarimer/9537092 to your computer and use it in GitHub Desktop.
Save dustinlarimer/9537092 to your computer and use it in GitHub Desktop.
GeoCharts with Keen IO

GeoCharts with Keen IO

This recipe uses geographic properties generated by the ip_to_geo data enrichment addon.

If you would like to activate this addon for your project, just ask!

The team is available in HipChat, IRC, or at contact@keen.io.

<html>
<head>
<title>GeoCharts with Keen IO</title>
<script src="https://dc8na2hxrj29i.cloudfront.net/code/keen-2.1.2-min.js"></script>
<script>
Keen.configure({
projectId: "your_project_id",
readKey: "your_read_key"
});
Keen.onChartsReady(function() {
var data = [["Country", "Count"]], options = {}, datatable, chart;
var countries = new Keen.Metric("pageview", {
analysisType: "count",
groupBy: "keen_ip_geo_info.country",
timeframe: "this_week"
});
countries.getResponse(function(response){
for (var i = 0; i < response.result.length; i++) {
data.push([response.result[i]["keen_ip_geo_info.country"], response.result[i]["result"]]);
}
options = {};
datatable = google.visualization.arrayToDataTable(data);
chart = new google.visualization.GeoChart(document.getElementById("map"));
chart.draw(datatable, options);
});
});
</script>
</head>
<body>
<div id="map"></div>
</body>
</html>
@nlashinsky
Copy link

This is pretty radical!

@albertovasquez
Copy link

Just a quick update keen_ip_geo_info.country should be replaced with just ip_geo_info.country

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment