privacycg / private-click-measurement

Private Click Measurement
https://privacycg.github.io/private-click-measurement/
196 stars 8 forks source link

Issues with Fetching Data on Click Events Using the Webkit PCM API #110

Open Yuyan-Lei opened 7 months ago

Yuyan-Lei commented 7 months ago

Hi,

I am currently testing third-party measurement using the Webkit Private Click Measurement API and have set up a simulated environment on Glitch with a sample publisher site, advertiser site, and adTech site for this purpose. I have created an ad on the adTech site, which is displayed on the publisher site via an iframe. The demo can be accessed at https://c-3-publisher.glitch.me, and https://c-3-adtech.glitch.me.

One of my goals is to track the number of users who click on the ad but do not complete a conversion. To accomplish this, I need to record the click data whenever a user clicks on the ad. I have implemented a fetch request in the ad's onClick event handler to send this data to another server for recording. Below is the code for the example ad.

<div>
  <a
    id="ad"
    href="https://c-3-advertiser.glitch.me"
    attributionsourceid="2" 
    attributiondestination="https://c-3-advertiser.glitch.me"
    target="_top"
    onClick = () => {
      fetch(`[url]`, { method: "GET" })
      .catch((error) => {
        console.error("PCM fetch error: ", error);
      });
    }
  >
    <img
      src="[srcUrl]"
      width="100%"
    />
  </a>
</div>

I followed the example code provided in the Webkit repo (webkit: //github PCM: Allow measurement of links in nested, cross-site iframes ), using target="_top" in the iframe to ensure that when users click on an ad, they are redirected to the advertiser's page instead of loading it within the iframe. However, I've encountered an issue where the fetch request fails after successfully storing a click. This seems to occur because once the ad is clicked, the browser initiates a new page load, interrupting the execution of scripts on the current page, including any incomplete asynchronous fetch requests.

As a control experiment, I also tested with target="_blank", where a new tab opens to display the advertiser's site when the user clicks the ad. While the fetch operation succeeds in this scenario, the browser does not recognize it as a valid PCM click, and no "storing a click" log appears in the console.

Based on the testing above, I have two questions regarding this issue:

  1. Is there a workaround or solution to successfully execute the fetch request in this scenario?

  2. Is it necessary to use target="_top" in the iframe to ensure that the browser recognizes a user's click on the iframe as a successful PCM click?

Thank you for any insights or assistance you can provide!

AramZS commented 7 months ago

Hi all, @Yuyan-Lei is working with the team at The Washington Post on our overall testing of various privacy measures from a publisher perspective. This question comes out of some of our tests.