Skip to content

Commit

Permalink
Define type for stored impressions and use it in algorithms
Browse files Browse the repository at this point in the history
CC #63
  • Loading branch information
apasel422 committed Jan 30, 2025
1 parent 0f49386 commit 6402c09
Showing 1 changed file with 37 additions and 42 deletions.
79 changes: 37 additions & 42 deletions api.bs
Original file line number Diff line number Diff line change
Expand Up @@ -676,18 +676,17 @@ for=PrivateAttribution>measureConversion()</a> method to find matching

### Contents ### {#impression-store-contents}

The [=impression store=] must store the following information:
The [=impression store=] must store the following information per [=impression=]:

<div link-for=PrivateAttribution>
<div dfn-for=impression link-for=PrivateAttribution>
<pre class=simpledef>
Filter Data: The {{PrivateAttributionConversionOptions/filterData}} value passed to <a>saveImpression()</a>.
Impression Site: The site that called <a>saveImpression()</a>.
Intermediary Site: The site corresponding to the script that called <a>saveImpression()</a>.
Conversion Sites: The conversion site(s) that were passed to <a>saveImpression()</a>.
Timestamp: The time at which <a>saveImpression()</a> was called.
Lifetime: The number of days an [=/impression=] remains eligible for attribution,
Lifetime: either from the call to <a>saveImpression()</a>, or a [=/user agent=]-defined limit.
Histogram Index: The histogram index passed to <a>saveImpression()</a>.
<dfn>Filter Data</dfn>: The {{PrivateAttributionConversionOptions/filterData}} value passed to <a>saveImpression()</a>.
<dfn>Impression Site</dfn>: The site that called <a>saveImpression()</a>.
<dfn>Intermediary Site</dfn>: The site corresponding to the script that called <a>saveImpression()</a>.
<dfn>Conversion Sites</dfn>: The conversion site(s) that were passed to <a>saveImpression()</a>.
<dfn>Timestamp</dfn>: The time at which <a>saveImpression()</a> was called.
<dfn>Lifetime</dfn>: The number of days an [=/impression=] remains eligible for attribution, either from the call to <a>saveImpression()</a>, or a [=/user agent=]-defined limit.
<dfn>Histogram Index</dfn>: The histogram index passed to <a>saveImpression()</a>.
</pre>
</div>

Expand Down Expand Up @@ -775,9 +774,9 @@ the process will set a value of zero for all histogram buckets.
To <dfn>fill a histogram using last-touch attribution</dfn>,
given <a dictionary lt=PrivateAttributionConversionOptions>|options|</a>:

1. Initialize |impression| to a null value.
1. Let |impression| be null.

1. Initialize |value| to |options|.{{PrivateAttributionConversionOptions/value}}.
1. Let |value| be |options|.{{PrivateAttributionConversionOptions/value}}.

1. Let |now| be the current time.<!-- TODO: cite HRTIME spec -->

Expand All @@ -787,35 +786,30 @@ given <a dictionary lt=PrivateAttributionConversionOptions>|options|</a>:
1. Let |impressions| be the result of invoking [=common matching logic=]
with |options|, |epoch|, and |now|.

1. If |impressions| is not empty:
1. If |impressions| [=set/is empty|is not empty=]:

1. Retain the value of |epoch|.
1. Retain the value of |epoch|.<!-- TODO: Clarify "Retain" -->

1. Set |impression| to the value in |impressions|
with the most recent |impression|.timestamp.
<!-- TODO define a type for stored impressions -->
with the most recent [=impression/timestamp=].

1. Exit the loop.
1. [=iteration/Break=].

1. If |impression| is null, let |budgetOk| be false.
1. Let |histogram| be a [=list=] of [=list/size=]
|options|.{{PrivateAttributionConversionOptions/histogramSize}}, whose
[=list/items=] are all 0.

1. Otherwise, let |budgetOk| be the result of [=deduct privacy budget=]
with |epoch| and |options|.{{PrivateAttributionConversionOptions/epsilon}}.
1. If |impression| is not null:

1. If |budgetOk| is false, set |value| to 0.
1. Let |budgetOk| be the result of [=deduct privacy budget=]
with |epoch| and |options|.{{PrivateAttributionConversionOptions/epsilon}}.

1. If |impression|.<var ignore=''>histogramIndex</var>
is |options|.{{PrivateAttributionConversionOptions/histogramSize}} or greater,
set |value| to 0.
1. Let |index| be |impression|'s [=impression/histogram index=].

1. If |value| is not 0, set |index|
to |impression|.{{PrivateAttributionImpressionOptions/histogramIndex}}.
1. If |budgetOk| is true and |index| is less than |histogram|'s
[=list/size=], set |histogram|[|index|] to |value|.

1. Otherwise, set |index| to 0.

1. Return a histogram containing |options|.{{PrivateAttributionConversionOptions/histogramSize}} values,
with a value of |value| at an index of |index|
and a value of zero at all other indices.
1. Return |histogram|.


### Common Impression Matching Logic ### {#logic-matching}
Expand All @@ -827,25 +821,26 @@ Discuss "infinite" lookbackDays. Clarify when it apples. When field is missing?
To perform <dfn>common matching logic</dfn>,
given |options|, |epoch|, and [=moment=] |now|:

1. If number of days since the end of |epoch| exceeds |lookbackDays|,
return an empty set.
1. Let |matching| be an [=set/is empty|empty=] [=set=].

1. Initialize |matching| to an empty set.
1. If number of days since the end of |epoch| exceeds |lookbackDays|,
return |matching|.<!-- TODO: Define a day -->

1. For each |impression| in the saved impressions for the |epoch|:
1. [=set/iterate|For each=] |impression| in the [=impression store=] for the |epoch|:
<!-- TODO: Clarify "for the |epoch|" -->

1. If |now| - |lookbackDays| is after |impression|.timestamp,
continue the loop.
1. If |now| - |lookbackDays| is after |impression|'s [=impression/timestamp=],
[=iteration/continue=].

1. If |options|.{{PrivateAttributionConversionOptions/filterData}}
does not match |impression|.filterData,
continue the loop.
does not match |impression|'s [=impression/filter data=],
[=iteration/continue=].<!-- TODO: Clarify "does not match" -->

1. If |options|.{{PrivateAttributionConversionOptions/impressionSites}}
does not contain |impression|.impressionSite,
continue the loop.
does not [=list/contain=] |impression|'s [=impression/impression site=],
[=iteration/continue=].

1. Add |impression| to |matching|.
1. [=set/Append=] |impression| to |matching|.

1. Return |matching|.

Expand Down

0 comments on commit 6402c09

Please sign in to comment.