Quickly clearing out your Facebook advert ‘interests’
2020 EDIT: This solution is now packaged up as a nice browser extension. Click here to read the new post for details and links to the browser extension.
Over the past years, Facebook have had a few privacy related issues. First came the ‘scandal’ with Cambridge Analytica and more recently a bug (or series of bugs) that apparently affected 50 million accounts allowing peoples access tokens to be stolen. Oh, and there was also the story about Facebook using your 2 factor authentication phone number for targeting advertising.
With all of the goings on recently, as well as the new GDPR (General Data Protection Regulation) in the EU, Facebook have attempted to make the data that they have about an individual easier to see, understand and edit or remove. One such section of this data covers your “ad preferences“.
What is actually included here?
Starting at the bottom, there are three pretty fine grained tabs “Hide ad topics”, “Ad settings” and “Your information” that provide you with some control controls and in theory limit some of the data that Facebook will use while targeting.
The top two sections are far more general and contain multiple categories and elements within the categories. “Your interests” includes various interests that Facebook has decided that you have and should be targeting using. “Advertisers you’ve interacted with” shows any interaction with advertisers, including website visits, advert clicks, and advertisers manually adding your contact details it would seem.
Having a little scroll through all of the information here can be quite interesting. I struggle to see how Facebook has made some of the links that it has recorded here for my account, but I have been using Facebook for many years. What on earth is “The Suburban Collection” and why am I apparently interested in it?
Usability for removal
The two larger sections definitely look nice, but are they really that useable? No not really.
My interests section is split over 10 separate categories, each with their own tab for access. Each tab also does not display all interests at once, instead the user is forced to repeatedly click the “See more” link and scroll down the page, tens or hundreds of times. And then I have to target a small X in the top right of each interest box to remove it. No, there is no select all. At least there is no confirmation… It’s almost like Facebook doesn’t want to make removing this stuff easy.
A little bit of JavaScript
I figured rather than spending my time clicking on the thousands of elements that I would need to in order to removal all interests and advertisers that I have interacted with I would knock up a little bit of JavaScript.
I worked on a few different iterations but didn’t want to spend too much time on the problem so I ended up with the small functions below.
The code below was last updated on 15 October 2019 with an alteration from a comment. Using the browser extension linked above is recommended.
NOTE: Please only run this code if you know what you are doing/understand the code below. This code is licensed with the Unlicense.
// This is free and unencumbered software released into the public domain.
// For more information, please refer to <http://unlicense.org/>
// Find and return the position of the element given
function findPos(obj) {
var curtop = 0;
if (obj.offsetParent) {
do {
curtop += obj.offsetTop;
} while (obj = obj.offsetParent);
return [curtop];
}
}
// Click on the "See more" link
// Updated from https://addshore.com/2018/10/quickly-clearing-out-your-facebook-advert-interests/#comment-386
function clickSeeMore() {
found = true
while(found == true) {
var seeMore = document.evaluate('//div[text()=\'See More\']', document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
if(seeMore) {
window.scroll(0,findPos(seeMore)-200);
seeMore.click();
} else {
found = false;
}
}
}
// Click on all X / Remove buttons currently on the page
function clickAllX(){
var allX = document.evaluate('//button[@data-tooltip-content=\'Remove\']', document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
for (i=0; i<allX.snapshotLength; i++) {
var next = allX.snapshotItem(i);
window.scroll(0,findPos(next)-200);
next.click();
}
}
// Combination, Click "See more" and then click all "Remove" buttons
function seeMoreAndClickXs() {
clickSeeMore()
clickAllX()
}
Code language: JavaScript (javascript)
This can be directly copy and pasted into the developer console while browsing the “Ads interests” page. Then to run one iteration of the code that will click on “See more” once, followed by clicking on all “Remove” buttons currently visible just run the seeMoreAndClickXs() function with the following:
seeMoreAndClickXs()
Of course you will probably have to run this function multiple times. If you run it and still see the “See more” link at the bottom of the section, then run it again!
Whats next?
Of course the developer console is going to warn you about the possibility of XSS attacks. Running things like this in the developer console isn’t ideal for the masses. Please only do things your comfortable with, give https://www.facebook.com/selfxss a read. Maybe I should turn this into a browser extension…
Ideally Facebook would just make their UX a little better. Why isn’t there just a “Remove all” button?
It would also be nice if this could be a single click thing, rather than having to run this function multiple times. But I couldn’t really get that done in the 15 minutes I dedicated to this task.
Interestingly although all of these interests are “Removed”, facebook still has this data about you, as it continues to list all of the removed interests. I wonder if they go away after a period of time? I imagine not. I wonder if GDPR allows for requests for specific information like this to be removed?
I also have no idea if Facebook was actually using this data in the first place, given my “Ad settings” specify that various types of Ads are already not allowed.
Thanks for this. It’s not working however I’ve been looking to do something similar so may adapt this!
I imagine the page layout / html has changed since I wrote the post :(
It could be worth having something like this as a browser extension.
Just to let you know, someone posted a new version of the code in a comment below.
It might be worth you giving that a go if your looking into this still.
I updated the script a bit as it was tossing errors. I changed it to click the link directly and loop until it was done:
// For more information, please refer to http://unlicense.org/
// Find and return the position of the element given
function findPos(obj) {
var curtop = 0;
if (obj.offsetParent) {
do {
curtop += obj.offsetTop;
} while (obj = obj.offsetParent);
return [curtop];
}
}
// Click on the “See more” link
function clickSeeMore() {
var found = “”;
for (var i = 0; i < aTags.length; i++) {
if (aTags[i].textContent == searchText) {
found = aTags[i];
break;
}
}
var seeMore = found;
//window.scroll(0,findPos(seeMore)-200);
if( seeMore != “” ) {
seeMore.click();
}
return found;
}
// Click on all X / Remove buttons currently on the page
function clickAllX(){
var allX = document.evaluate(‘//button[@data-tooltip-content=\’Remove\’]’, document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
for (i=0; i
}
// Combination, Click “See more” and then click all “Remove” buttons
function seeMoreAndClickXs() {
var found = “something”;
while( found != “” ) {
found = clickSeeMore();
clickAllX()
}
}
Tested on 08/21/19 in Chrome
Amazing! It would be great to start a browser extension with a collection of little snippets like this for features that Facebook should really provide.
I have updated the post to include an edit linking to this comment!
This won’t work – it looks like there are pieces missing.
From what I can tell, the only thing wrong with the original solution is case – changing the string to “See More” fixed it for me.
I was also able expand the list fully and then click all the X’s at once by adding a loop to clickSeeMore():
function clickSeeMore() {
found = true
while(found == true) {
var seeMore = document.evaluate('//div[text()=\'See More\']', document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
if(seeMore) {
window.scroll(0,findPos(seeMore)-200);
seeMore.click();
} else {
found = false;
}
}
}
Thanks for this.
I have just updated the code in the post with a link to the comment and tested it on my account again (all working).
Curiously, I found that when clicking all the X’s at once, everything looks OK in my browser, but nothing changes upon page refresh. I seem to have better results just clicking the X’s without expanding the list, but even then it seems unreliable. It’s almost as if they don’t want you to alter your ad preferences…
Are you seeing the same thing? I don’t understand this behavior but I’m clueless about JS.
Unfortunately I cannot even OPEN MY Interests, let alone close each collectively or individually. Facebook does NOT respond to pleas for help!
What happens when you try to open your interests?
Thanks for your reply .
I get an error message:
Trouble loading, tap to retry.
No matter how many times I tap to retry, or exit and retry, same error.
On my phone and on the laptop.
Works for me!
Ok, 1st, THANK YOU! This is super helpful! However, even though it shows “You removed”, when you refresh the screen, ALL of them are back! Guaranteed! WTF is going on here Facebook!?
Yup, i also agree, wtf facebook. It could be some sort of rate limiting.
I don’t have have a great idea to figure out how to fix that or figure out exactly what is happening.
I tried waiting for a bit between clicks but this also didn’t seem to work.
Thank you! This worked for me to clear those things out much faster. It stuck for the first ones, then I just had to reload to get the next “tab” for it to work again. It also worked great for quickly clicking Hide all ads by just changing the Remove text 🙂
Thanks!
I had to change the function clickSeeMore() to look for “See more” rather than “See More”
other than that – works perfectly.
If you have liked a lot of things it’s practically infeasible to clear without a select all. Shame on you facebook.
It looks like this is due to the slight differences on Facebook between US and UK English translations.
I’m just about to rewrite this into a browser extension which will take this into account, although it won’t work in other languages.
Works for me when I changed to language english
Ahh yes, it uses an English string to find the elements, so it will indeed only work in English!
[…] the end of 2018, I wrote a blog post that included some JavaScript code to quickly remove all of your Facebook advert interests from […]
Thank you so much! Just ran this today on my facebook – took some time but it did work. Much faster than having to do it manually. Thank you!
I’m getting that error message when I try to click Your Interests. I was able to get in successfully yesterday. But then after a while it stopped working.
[…] Quickly clearing out your Facebook advert ‘interests’ (was #6) […]
The script stopped working, possibly a UI change.
Hi Luke!
I took a quick look and it seems to be working for me.
I also made https://github.com/addshore/browser-facebook-advert-interest-cleaner/issues/8 to track this.
What URL is being used?
What language is being used?
What is happening (rather than the expected)
[…] really easy to see how a single post can skew growth year by year. That post last year was Quickly clearing out your Facebook advert ‘interests’ which alone brought in 10k views, this year reducing to 3k. The peak post of 2020 only has around […]
[…] Quickly clearing out your Facebook advert ‘interests’ (was #4 ⬇️) […]