Skip to content
Merged
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
9 changes: 5 additions & 4 deletions api.bs
Original file line number Diff line number Diff line change
Expand Up @@ -724,7 +724,8 @@ contribute to the histogram, i.e., will be uniformly zero.

<xmp highlight=js>
const attributionDetails = {
credit: [.25, .25, .5]
// top impression's histogram index gets 50% of value, the next two 25% each
credit: [.5, .25, .25],
value: 3,
maxValue: 7,
};
Expand Down Expand Up @@ -1815,11 +1816,11 @@ To <dfn>fill a histogram with last-n-touch attribution</dfn>, given a [=set=] of
a [=list=] of doubles |credit|:

1. [=Assert=]: |matchedImpressions| is [=set/is empty|not empty=].
1. Let |sortedImpressions| be |matchedImpressions|, [=list/sorted in ascending order=]
1. Let |sortedImpressions| be |matchedImpressions|, [=list/sorted in descending order=]
by [=impression/priority=], then by [=impression/timestamp=].
1. Let |N| be the minimum of the [=list/size=] of |credit|, and the [=list/size=] of |sortedImpressions|.
1. Let |lastNImpressions| be the last |N| entries of |sortedImpressions|.
1. [=list/remove|Remove=] all but the last |N| entries of |credit|.
1. Let |lastNImpressions| be the first |N| entries of |sortedImpressions|.
1. [=list/remove|Remove=] all but the first |N| entries of |credit|.
1. Let |normalizedCredit| be the result of [=fairly allocate credit|fairly allocating credit=] with |credit| and |value|.
1. Let |histogram| be the result of invoking [=create an all-zero histogram=]
with |histogramSize|.
Expand Down
29 changes: 29 additions & 0 deletions impl/e2e-tests/credit-longer-than-impressions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"events": [
{
"seconds": 1,
"site": "publisher.example",
"event": "saveImpression",
"options": { "histogramIndex": 0 }
},
{
"seconds": 2,
"site": "publisher.example",
"event": "saveImpression",
"options": { "histogramIndex": 1 }
},
{
"seconds": 3,
"site": "advertiser.example",
"event": "measureConversion",
"options": {
"aggregationService": "https://agg-service.example",
"histogramSize": 4,
"value": 12,
"maxValue": 12,
"credit": [6, 3, 3]
},
"expected": [4, 8, 0, 0]
}
]
}
36 changes: 36 additions & 0 deletions impl/e2e-tests/multi-touch-divides-evenly-unordered-credit.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"events": [
{
"seconds": 1,
"site": "publisher.example",
"event": "saveImpression",
"options": { "histogramIndex": 0 }
},
{
"seconds": 2,
"site": "publisher.example",
"event": "saveImpression",
"options": { "histogramIndex": 1 }
},
{
"seconds": 3,
"site": "publisher.example",
"event": "saveImpression",
"options": { "histogramIndex": 2 }
},
{
"seconds": 4,
"site": "advertiser.example",
"event": "measureConversion",
"options": {
"aggregationService": "https://agg-service.example",
"histogramSize": 4,
"value": 8,
"maxValue": 10,
"credit": [1, 2, 1]
},
"$comment": "not necessarily useful, but demonstrates the ability to prefer the second-to-last over the last",
"expected": [2, 4, 2, 0]
}
]
}
35 changes: 35 additions & 0 deletions impl/e2e-tests/multi-touch-divides-evenly.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"events": [
{
"seconds": 1,
"site": "publisher.example",
"event": "saveImpression",
"options": { "histogramIndex": 0 }
},
{
"seconds": 2,
"site": "publisher.example",
"event": "saveImpression",
"options": { "histogramIndex": 1 }
},
{
"seconds": 3,
"site": "publisher.example",
"event": "saveImpression",
"options": { "histogramIndex": 2 }
},
{
"seconds": 4,
"site": "advertiser.example",
"event": "measureConversion",
"options": {
"aggregationService": "https://agg-service.example",
"histogramSize": 4,
"value": 8,
"maxValue": 10,
"credit": [2, 1, 1]
},
"expected": [2, 2, 4, 0]
}
]
}
45 changes: 45 additions & 0 deletions impl/e2e-tests/priority.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{
"events": [
{
"seconds": 1,
"site": "publisher.example",
"event": "saveImpression",
"options": {
"histogramIndex": 0,
"priority": 200
}
},
{
"seconds": 2,
"site": "publisher.example",
"event": "saveImpression",
"options": {
"histogramIndex": 1,
"priority": 300
}
},
{
"seconds": 3,
"site": "publisher.example",
"event": "saveImpression",
"options": {
"histogramIndex": 2,
"priority": 200
}
},
{
"seconds": 4,
"site": "advertiser.example",
"event": "measureConversion",
"options": {
"aggregationService": "https://agg-service.example",
"histogramSize": 4,
"value": 8,
"maxValue": 10,
"credit": [6, 2]
},
"$comment": "index 1 has the highest priority; the others have equal priority but index 2 is most recent",
"expected": [0, 6, 2, 0]
}
]
}
4 changes: 2 additions & 2 deletions impl/src/backend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -532,10 +532,10 @@ export class Backend {
const sortedImpressions = Array.from(matchedImpressions).toSorted(
(a, b) => {
if (a.priority < b.priority) {
return -1;
return 1;
}
if (a.priority > b.priority) {
return 1;
return -1;
}
return Temporal.Instant.compare(b.timestamp, a.timestamp);
},
Expand Down