Everywhere we can see people complaining that they can no longer click on google ads when using Pi-hole. The answers are always the same: works as intended, look further down.
When I looked at the blocked URLs, I saw the URL that I really wanted after "adurl=". E.g.
> https://www.googleadservices.com/pagead/aclk?...&adurl=wantedUrl
. The approach is to strip everything before adurl= and redirect to the wanted URL. Sometimes it is more complicated than this, because adurl refers to another ad server, like ad.doubleclick.net, then the wanted url is in another parameter.
I test this approach with a small Chrome extension. It has just two files. Put them in an empty directory, and call chrome://extensions/ , then "load unpacked from directory" or so. The two files are
manifest.json:
{
"name": "pihole_googleads",
"description": "make google ads usable for Pihole",
"version": "1.0",
"manifest_version": 3,
"declarative_net_request": {
"rule_resources": [{
"id": "ruleset",
"enabled": true,
"path": "rules.json"
}]
},
"permissions": [
"declarativeNetRequest"
],
"host_permissions": [
"https://www.googleadservices.com/*"
]
}
and rules.json:
[
{
"id": 1,
"priority": 2,
"action": {
"type": "redirect",
"redirect": {
"regexSubstitution": "\\1"
}
},
"condition": {
"regexFilter": "^https://www.googleadservices.com/.*adurl=https://ad.doubleclick.net/.*_clickid_%3F(.*)%3F.*",
"resourceTypes": [ "main_frame" ]
}
},
{
"id": 2,
"priority": 2,
"action": {
"type": "redirect",
"redirect": {
"regexSubstitution": "\\1"
}
},
"condition": {
"regexFilter": "^https://www.googleadservices.com/.*adurl=https://clickserve.dartsearch.net/.*ds_dest_url%3D(.*)%3F.*",
"resourceTypes": [ "main_frame" ]
}
},
{
"id": 3,
"priority": 1,
"action": {
"type": "redirect",
"redirect": {
"regexSubstitution": "\\1"
}
},
"condition": {
"regexFilter": "^https://www.googleadservices.com/.*adurl=(.*)%3F.*",
"resourceTypes": [ "main_frame" ]
}
},
{
"id": 4,
"priority": 1,
"action": {
"type": "redirect",
"redirect": {
"regexSubstitution": "\\1"
}
},
"condition": {
"regexFilter": "^https://www.googleadservices.com/.*adurl=(.*)",
"resourceTypes": [ "main_frame" ]
}
}
]
Basically, the condition specifies a regexp, and the part in () is referred to in regexSubstitution as \1.
The 3F-stuff is there, because the url after adurl is urlencoded, and I can not find out how to unencode before redirect. The 3F is the question mark, so essentially the wanted URL is stripped from the parameters.
I know this is very rough, but I looked into Chrome Extensions only for a few hours, and my hope is, that someone who reads this comes up with something more polished.
I tested this on a few ads, and I was quite pleased.