How to Anonymize New Analytics

James
Community Champion
5
2500

Have you ever wanted to do a live demonstration of New Analytics with a real course but couldn't because of student privacy issues? Fake students in a fake course don't generate realistic usage. New Analytics pulls information from the production instance so you cannot hop over to beta and change the names. Making a video and blurring out names doesn't have the same impact as presenting live. What can one do?

I've written a Firefox browser extension that anonymizes the user's name, email, sortable name, short name, and optionally removes the avatars so that you can give a live demonstration without worry about accidentally showing student information. The extension is loaded temporarily so that New Analytics reverts back to normal after restarting Firefox.

Introduction

First, this extension works only with Firefox. Yes, I know I normally write things that work with any browser, but Firefox is the only browser to support modifying a network response that contains the user information.

This extension looks for GraphQL queries made to the New Analytics server and modifies the response before passing it on to New Analytics JavaScript that runs in the browser and displays the content. It modifies the student information and looks for any user page in the assets (resources) to change them as well.

For example, let's say that a student named James Jones has an email address of james@richland.edu. The extension may convert that to Wild Feather with an email address of wild_feather@example.com. When the data is delivered to the New Analytics in the browser, it only sees Wild Feather and wild_feather@example.com. That means that it can only display the Wild Feather information because that is all that it sees. This also means that names are shown alphabetically by the aliases, not by the original names.

Here is a video introduction that shows what New Analytics looks like before and after installing the anonymizer extension.

The extension comes preloaded with 123 names composed mostly of adjectives followed by nouns like Wild Feather, Puny Ego, or Acidic Mob. If you view more than 123 students, it will shuffle the adjectives and nouns to come up with other names like Wild Mob or Puny Feather. Theoretically, you can have up to 1232=15,129 different students before it runs out of names. In reality it will be less, but it should be good enough for most video purposes. If you do run out of names, it still start reusing existing names. You can edit the code and change the names if you like.

The email is formed from the user alias (anonymous name) and you can control the format of the email to make it look more like one of your institutions emails.

The aliases persist for a browser session. If James Jones becomes Wild Feather and you reload New Analytics, that connection will persist. If you go off to another course, look at New Analytics, and come back, the connection between James and Wild will still be there. As long as you don't restart Firefox or reload the extension, the aliases persist. This allows you to prepare ahead of time to find interesting students to demonstrate in your presentation. What you cannot know ahead of time is that James will become Wild. Each time you reload the extension, a random assignment occurs. If you do need to know what someone's alias is, find something unique like the page views ahead of time and then locate them once the names are anonymized.

Installation

Remember that this extension works only with Firefox.

Here is a video showing how to install the files from my GitHub page. The first part will be easier if you follow the written steps below since I have direct links to the files rather than having to navigate through GitHub. The second part about installing in Firefox is the same as the written instructions below.

Step 1: Save the Files Locally

This step can be done using any browser. Firefox actually had some issues for me, so you might want to use something else for this step.

  1. Create a folder on your hard drive.
  2. Download the manifest.json and analytics.js files and save them into that folder. You can right click on each filename and choose Save Link As in your browser to do this.
  3. Optionally edit the analytics.js file and change the configuration options.

Note that when I tried to save analytics.js with Firefox, it added a .txt extension that must be removed before the program can be used. Chrome didn't have that issue for me, so that is why I recommend using a different browser than Firefox for this step.

This step only needs done once.

Step 2: Install the Extension in Firefox

I know you're going to get tired of me saying this, but this extension will work only with Firefox.

This step needs performed each time you want to anonymize the names. The extension is loaded temporarily into Firefox and will stop when you restart the browser or remove the extension. Most of the time you will not want this extension running, so I didn't want it to be permanent.

  1. In the Firefox location bar, type about:debugging and press enter.
  2. On the left side, click on This Firefox.
  3. Under Temporary Extensions, click on Load Temporary Add-on.
  4. Navigate to the folder where you saved the files, select any file in the folder, and click Open.

That's it. The next time you load New Analytics the names will be anonymized.

The Temporary Extensions section allows you to reload the extension. This will restart the randomization or recognize any changes to the configuration settings in the analytics.js file without having to restart the browser. You can also remove the extension here without having to restart the browser. Restarting Firefox will remove the extension as it is only loaded temporarily.

Configuration

There are three settings that you can configure in the analytics.js file. If you edit them after loading the extension, you will need to reload the extension.

  • emailFormat determines what you want the username portion of the email address will look like. The username portion is derived from the anonymous name. The examples below show how "Wild Feather" would appear.
    • flast is the first initial followed by the last name (wfeather)
    • lastf is the last name followed by the first initial (featherw)
    • first_last is the first name, underscore, and then last name (wild_feather). This is the default unless you change the configuration.
    • last_first is the last name, underscore, and then first name (feather_wild)
  • defaultDomain determines the domain name to use for the email address.
    • empty string '' or null will keep the existing domain of the user.
    • non-empty string such as 'example.com' will force the domain to that string. The default is example.com.
    • comma-separated string such as 'gmail.com,yahoo.com,hotmail.com,outlook.com,icloud.com' will randomly assign one of those domains to the email.
  • removeAvatar determines whether to remove the avatars.
    • true will remove the avatars and just use the initials of the alias. This is the default setting.
    • false will keep the existing avatar of the user.

There is one additional item that you can change, but it is is inside a function inside of a variable. The anonymousUserList function contains a comma-separated list of 123 potentially-humorous names that mostly consist of an adjective followed by a noun. You can go through and alter this as you see fit. The list was automatically obtained from a now-defunct website and I did not scrutinize them for offensive names.

If you happen to have view more students than you have aliases (123 in the default configuration), the script will the first names and last names into two separate lists, shuffle each of those, and recombine them into new names. For example, if "Puny Ego" and "Normal Rockstar" are original alises, a reshuffle might give you "Puny Rockstar" and "Normal Ego". If you exhaust the new list of names, then it will repeat that process, making sure that no name is duplicated. Theoretically, if there are n names, then there are n2 combinations. For the default 123 names, you can view up to 15129 students without running into duplication problems. In reality, you will not achieve the maximum because of the way the process is done. If you view so many students that it cannot generate new names, the script will start reusing names.

About

My wife had two New Analytics demonstrations coming up and was looking for ways to present the results of a real course. She did not want to make a video and blur out the names and then show the video, she wanted a live presentation.

We had looked at this problem before when she had presented on New Analytics. We thought that by going into the beta instance and changing the names that she would be good. Unfortunately, New Analytics is updated once a day and we missed the deadline. It wouldn't have mattered anyway because New Analytics is an LTI and LTIs pull their information from the production instance, even if you're running them in the beta instance. That means we would have to change the names and logins for real students at least a day before the presentation. That isn't going to happen since those real students need to log into Canvas to do their coursework.

I originally tried to accomplish the anonymization using a userscript and Tampermonkey by rewriting the information every time it appeared. This was nightmarish, with lots of mutation observers and changing something to just to find it reappeared later, and when I thought I had something working, my wife found a spot I had missed with about her third click. It turned out that I missed a lot of spots and things that worked the first time you viewed them didn't work after returning to the main page from looking at a student.

I thought about using the ability for Chrome to override JavaScript with local changes, but that makes maintenance a nightmare to configure, people wouldn't get updates from Canvas, and I would be forced to update the script every time Canvas changed something in New Analytics. That notion got less than 5 seconds of consideration before moving on.

We went on our first family vacation since COVID and when I came back, I started looking into the possibility of intercepting the network data before Canvas saw it. I had done this with some other scripts using window.XMLHttpRequest method, but Canvas doesn't use that here. I tried to replace the window.fetch method, but Canvas doesn't use it, either. The webRequest API looked like the way to go, but I quickly discovered the Chrome doesn't support modifying the response unless you do a hack by loading the developer tools and leaving it open while you do the operations. Firefox was the only browser that supported modifying the response and when my wife said she could use Firefox for the demonstration, that sealed the decision.

This is my first time trying a webRequest and so there may have been a better way to do things. But this works and it came together fairly quickly once I decided to go that route. The code that intercepts and rewrites the response data requires a blocking webRequest and Chrome is removing those in favor of Declarative Net Requests for privacy concerns (it says that 42% of malicious extensions use the webRequest API). This extension only looks at one URL, the GraphQL API for Canvas New Analytics (the full path is in the manifest.json file), and doesn't do any examination of the request itself, it only modifies the response. Since this doesn't work in Chrome to start with, their removal isn't an immediate concern, but Firefox often follows Chrome, so this may stop working at some point in Firefox as well. Until then, enjoy demonstrating New Analytics with anonymous users.

5 Comments