Skip to content

Instantly share code, notes, and snippets.

@jasonlally
Last active October 18, 2018 14:08
Show Gist options
  • Save jasonlally/179e80d30a9934836bb8 to your computer and use it in GitHub Desktop.
Save jasonlally/179e80d30a9934836bb8 to your computer and use it in GitHub Desktop.
Example code to track clicks on Socrata tracker buttons
//assuming jQuery is available
//attach events to the nav buttons above datasets
$('#sidebarOptions').on('click', 'a', function() {
var dataset = $('#datasetName').attr('title');
var label = $(this).attr('title');
//labels sent to google analytics on click events will include the dataset name and the label of the button
//this gives greater insight into how users are interacting with datasets once they arrive
ga('send', 'event', 'Data Panel', 'Click', dataset + ': ' + label);
});
$('.downloadsList').on('click', 'a', function() {
var dataset = $('#datasetName').attr('title');
var label = $(this).attr('data-type');
//labels sent to google analytics on click events will include the dataset name and the type of download file
//this gives greater insight into how users are interacting with datasets once they arrive
ga('send', 'event', 'Download', 'Click', dataset + ': ' + label);
});
@jasonlally
Copy link
Author

This could be abstracted so that a listener is attached to all links and then passes different data depending on the nature of the click. For example, an interface link vs. an external/download link.

For the code here, I've just focused on two of the interactions we're most interested in right now: what panels are people clicking on and are they downloading the data in raw formats. I've formatted the labels to make the analysis simpler so I can look at what people are clicking on and within what dataset.

@jasonlally
Copy link
Author

The code above is an attempt to operationalize insights we'd like to get to monitor the impact of the open data program overall.

The overarching question

How are people interacting with our data, once they discover it on DataSF?

The reason we want to answer this big question is to help classify the kinds of uses of our data and the types of users coming to the catalog.

For example, on a particular dataset, are people mostly downloading the data and in what format? Getting a lot of users downloading in excel, then that dataset may be being used by a lot of analysts? Or maybe we're getting a ton of JSON downloads indicating that developers are interested in the dataset and are poking around to see how the data's structured. Or are they mostly browsing and looking at the data? Maybe there's a dataset with lots of people clicking on about? Is there something about the dataset that indicates users looking for more metadata? These are just hypothetical examples of insights we could develop over time with some additional information. Having some baseline activity on downloads and panel clicks could help us develop deeper questions and identify outliers or patterns.

Summary questions

  • How many users are downloading data and in what formats?
    • Why? So we can more deeply understand the character of use and amount of use of a particular dataset.
  • What panels are users clicking on in the UI?
    • Why? So we can get a sense of what users are trying to figure out about a dataset, and more deeply understand user interactions on particular datasets.

Brittle code

We understand that the above may break as the platform changes, and we are completely understanding of that. For now it will be our responsibility to monitor changes and if we stop receiving click events on GA, we'll check in at the appropriate time. At this stage, even having just a couple of weeks of baseline would be better than nothing. And we want to make sure that we don't put undue burden on engineering in maintaining this custom code for us. In the longterm as the new platform settles, we would love to be helpful in thinking about deepening tracking as appropriate and inasmuch as our thinking helps shape future platform-wide analytics, we'd love to be helpful.

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