res.set(
"Attribution-Reporting-Register-Trigger",
JSON.stringify({
event_trigger_data: [
{
trigger_data: "4",
priority: "1000000000000",
deduplication_key: "2345698765",
},
],
debug_key: "1115698977",
}),
);Registering attribution triggers / notebook
Registering attribution triggers
Runnable notebook: every JavaScript, HTML and CSS example on this page executes in a sandboxed local frame. Nothing leaves the browser.
res.set(
"Attribution-Reporting-Register-Trigger",
JSON.stringify({
aggregatable_trigger_data: [
{
key_piece: "0x400",
source_keys: ["campaignCounts"],
},
{
key_piece: "0xA80",
source_keys: ["geoValue", "nonMatchingKeyIdsAreIgnored"],
},
],
aggregatable_values: {
campaignCounts: 32768,
geoValue: 1664,
},
debug_key: "1115698977",
}),
);<img
src="https://shop.example/conversion/4rghshdh5"
alt=""
width="1"
height="1"
attributionsrc />const imgElem = document.querySelector("img");
imgElem.attributionSrc = "";<script src="advertising-script.js" attributionsrc></script>const scriptElem = document.querySelector("script");
scriptElem.attributionSrc = ""; const attributionReporting = {
eventSourceEligible: false,
triggerEligible: true,
};
// Optionally set keepalive to ensure the request outlives the page
function triggerMatching() {
fetch("https://shop.example/endpoint", {
keepalive: true,
attributionReporting,
});
}
// Associate the interaction trigger with whatever
// element and event makes sense for your code
elem.addEventListener("click", triggerMatching); const attributionReporting = {
eventSourceEligible: false,
triggerEligible: true,
};
function triggerMatching() {
const req = new XMLHttpRequest();
req.open("GET", "https://shop.example/endpoint");
// Check availability of setAttributionReporting() before calling
if (typeof req.setAttributionReporting === "function") {
req.setAttributionReporting(attributionReporting);
req.send();
} else {
throw new Error("Attribution reporting not available");
// Include recovery code here as appropriate
}
}
// Associate the interaction trigger with whatever
// element and event makes sense for your code
elem.addEventListener("click", triggerMatching);<img
src="https://shop.example/conversion/4rghshdh5"
alt=""
attributionsrc="https://my-separate-tracking-site.example.com"
width="1"
height="1" />const imgElem = document.querySelector("img");
imgElem.attributionSrc = "https://my-separate-tracking-site.example.com";