Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding iframe opt out #10

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ public class RouteConfiguration {
@Value("${templates.opt-in}")
private String optInTemplate;

@Value("${templates.iframe}")
private String iframeSync;

@Bean
public HandlerRegistry handlerRegistry(List<Handler<RoutingContext>> handlers) {
return new HandlerRegistry(handlers);
Expand Down Expand Up @@ -121,6 +124,11 @@ public Router router(Vertx vertx, HandlerRegistry handlerRegistry, TemplateEngin
.handler(handlerRegistry.get(ProcessOptInHandler.class))
.handler(TemplateHandler.create(templateEngine, optInTemplate, "text/html"));

router.get("/iframe/optout")
.handler(handlerRegistry.get(AddDefaultHeadersHandler.class))
.handler(CorsHandler.create(".*.").allowCredentials(true))
.handler(TemplateHandler.create(templateEngine, iframeSync, "text/html"));

router.get("/health")
.handler(new RespondHealthCheckHandler());

Expand Down
3 changes: 2 additions & 1 deletion src/main/resources/config/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ handlers.ccpa-consent.states=ca

templates.opt-out=templates/optout.hbs
templates.opt-in=templates/optin.hbs
templates.iframe=templates/iframe.hbs

handlers.template.template-dir=templates

gdpr.vendor-id=887
gdpr.vendor-id=887
57 changes: 57 additions & 0 deletions src/main/resources/templates/iframe.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<!doctype html>
<html lang="en">
<body>
<script type="application/javascript">
const OPT_OUT_VALUE = '00000000000000000000000000';
const prefix = 'SharedId.org'

function onLoad(fn) {
if (document.attachEvent ? document.readyState === "complete" : document.readyState !== "loading") {
fn();
} else {
document.addEventListener('DOMContentLoaded', fn);
}
}

function storageAccessAPISupported() {
return (
'hasStorageAccess' in document &&
'requestStorageAccess' in document
);
}

function onReady() {
console.info('Iframe loaded');
window.addEventListener('message', onMessage);
}

function onMessage(event) {
console.info('SharedID Received message :' + event + ' with event data ' + event.data);
if (event.data == 'optout-request') {
if (!storageAccessAPISupported()) {
console.info('STORAGE :Storage Access API not supported');
return;
}
document.requestStorageAccess()
.then(function () {
console.info('STORAGE : Storage API Access granted.');
setCookie('sharedid', "00000000000000000000000000");
return;
}, function () {
console.warn('STORAGE :Storage API Access denied.');
});
} else {
console.info('Received other messages :' + event + ' with event data ' + event.data);
}
}

function setCookie(name, value) {
document.cookie = name + "=" + value + ";" + ";path=/";
console.info('Setting optout cookies');
}

onLoad(onReady)

</script>
</body>
</html>