Page MenuHomePhabricator

Implement search activity id for Empty Search A/B test click tracking
Closed, ResolvedPublic3 Estimated Story Points

Description

Background

Context why we need a search activity id:
"The count of clicks is not reliable. For the click-through rate, a user must have a maximum of 1 click per 1 impression. However, in past projects, I sometimes observed more clicks than impressions. In such cases, I need to cap the clicks at 1 per search_session_id.
It’s quite common for event logging to miss some events. For example, we might receive click events but not the corresponding init events. Or we might expect to receive the same number of events for two equivalent triggers, but that’s not the case. I have put two examples in our 1:1 doc. Same thing could happen for any events in a sequence like user’s search journey. With search_session_id , we can exclude each search journey which missed impression events, or cap the clicks if they seems to be overcounted.
Without search session id, we cannot further clean the data. It might lead to inconclusive analysis result."

According to the spec, we need the search activity id associated with every click tracking event. This task is for adding code to WikimediaEvents that will manage search activity id, and ensure the search activity id is sent out with the click tracking

We can pull some of this code from searchSatisfaction.js in WikimediaEvents (i.e. how to generate the unique id), but their definition of a "search session" is more complicated, and describes a more general journey of a user trying to find information and potentially including multiple searches. Our definition is much simpler.

This patch will likely require code in MobileFrontend and WikimediaEvents

Requirements

A search activity is started when the searchbox receives focus.
A search activity is ended when the user exits the searchOverlay OR when the user proceeds with a search query/search recommendation link.

  • WikimediaEvents should generate a unique search activity id when the searchOverlay is opened. Note, this is different than ext.MobileFrontend.searchOverlay.empty.
  • Closing the searchOverlay should reset the search activity id
  • The search activity id should be send along with all the click tracking events
  • The search activity id should be logged as funnel_entry_token in all events

Acceptance criteria

  • Click tracking event for each search overlay should have a unique search activity id
  • The search activity id should be logged as funnel_entry_token in all events

BDD

Feature: Implement search activity ID for Empty Search A/B test click tracking  
  Scenario: Generate unique search activity ID when search overlay opens  
    Given a user focuses on the search box  
    When the search overlay opens  
    Then a unique search activity ID should be generated  

  Scenario: Reset search activity ID when search overlay closes  
    Given a user has an active search activity ID  
    When the user closes the search overlay  
    Then the search activity ID should be reset  

  Scenario: Include search activity ID in click tracking events  
    Given a user interacts with search recommendations or submits a query  
    When a click tracking event is fired  
    Then the event should include the search activity ID as funnel_entry_token  

  Scenario: Maintain the same search activity ID during a single search session  
    Given a user performs multiple actions within an open search overlay  
    When click tracking events are fired  
    Then the same search activity ID should be included in all events until the overlay is closed

Test Steps

Test Case 1: Verify unique search activity ID is generated when search overlay opens

  1. Open an incognito window and visit https://en.m.wikipedia.beta.wmflabs.org/w/index.php?title=T352930.
  2. Open the browser console and execute:
mw.loader.using('mediawiki.api').then(function () {  
  new mw.Api().saveOption('eventlogging-display-console', '1');  
});
  1. Click on the search box to open the search overlay.
  2. Observe the console logs for click tracking events.
  3. Verify that a unique search activity ID is generated and included as funnel_entry_token.
  4. AC1: A unique search activity ID is generated when the search overlay opens.

Test Case 2: Verify search activity ID is reset when search overlay closes

  1. Follow Test Case 1 to open the search overlay and generate an ID.
  2. Close the search overlay.
  3. Reopen the search overlay.
  4. Observe the console logs for new events.
  5. Verify that a new search activity ID is generated, different from the previous one.
  6. AC2: The search activity ID is reset when the search overlay is closed.

Test Case 3: Verify search activity ID is included in all click tracking events

  1. Open the search overlay as in Test Case 1.
  2. Interact with search recommendations (e.g., click on a suggestion).
  3. Submit a search query.
  4. Observe the console logs for click tracking events.
  5. Verify that each event includes the search activity ID as funnel_entry_token.
  6. AC3: The search activity ID is included in all click tracking events.

Test Case 4: Verify the same search activity ID is maintained within a single session

  1. Open the search overlay.
  2. Perform multiple actions without closing the overlay (e.g., type queries, click recommendations).
  3. Observe the console logs for click tracking events.
  4. Verify that all events share the same search activity ID.
  5. AC4: The same search activity ID is maintained during the session until the overlay is closed.

Communication criteria - does this need an announcement or discussion?

  • no

QA Results - Beta

Event Timeline

bwang triaged this task as High priority.Jan 16 2025, 8:59 PM
Jdlrobson changed the task status from Open to In Progress.Jan 16 2025, 10:12 PM
Jdlrobson set the point value for this task to 3.Jan 21 2025, 4:34 PM
Jdlrobson subscribed.

Per asynchronous estimation

Jdlrobson-WMF added a subscriber: Jdrewniak.

Change #1117948 had a related patch set uploaded (by Jdlrobson; author: Bernard Wang):

[mediawiki/extensions/WikimediaEvents@master] Add search activity id

https://gerrit.wikimedia.org/r/1117948

Change #1117948 merged by jenkins-bot:

[mediawiki/extensions/WikimediaEvents@master] Add search activity id

https://gerrit.wikimedia.org/r/1117948

Status: ✅ PASS
Environment: Beta
OS: macOS
Browser: Chrome
Device: MS MBA

Test Case 1: Verify unique search activity ID is generated when search overlay opens

  1. Open an incognito window and visit https://en.m.wikipedia.beta.wmflabs.org/w/index.php?title=T352930.
  2. Open the browser console and execute:
mw.loader.using('mediawiki.api').then(function () {  
  new mw.Api().saveOption('eventlogging-display-console', '1');  
});
  1. Click on the search box to open the search overlay.
  2. Observe the console logs for click tracking events.
  3. Verify that a unique search activity ID is generated and included as funnel_entry_token.
  4. AC1: A unique search activity ID is generated when the search overlay opens.
{
    "action": "click",
    "funnel_name": "Search related articles",
    "funnel_entry_token": "da74c9f3a969474ac4a8m6vjmo1t",
    "experiments": {
        "enrolled": [
            "RelatedArticles test experiment betacluster\t"
        ],
        "assigned": {
            "RelatedArticles test experiment betacluster\t": "experimentEnabled"
        }
    },
    "action_source": "search_box",
    "$schema": "/analytics/product_metrics/web/base/1.3.0",
    "mediawiki": {
        "site_content_language": "en",
        "skin": "minerva"
    },
    "performer": {
        "session_id": "c35a51529d3c957f6006",
        "is_logged_in": true
    },
    "agent": {
        "client_platform": "mediawiki_js",
        "client_platform_family": "mobile_browser"
    },
    "sample": {
        "rate": 1,
        "unit": "session"
    },
    "dt": "2025-02-08T01:55:25.889Z",
    "meta": {
        "stream": "product_metrics.web_base.search_ab_test_clicks",
        "domain": "en.wikipedia.beta.wmflabs.org"
    }
}

Test Case 2: Verify search activity ID is reset when search overlay closes

  1. Follow Test Case 1 to open the search overlay and generate an ID.
  2. Close the search overlay.
  3. Reopen the search overlay.
  4. Observe the console logs for new events.
  5. Verify that a new search activity ID is generated, different from the previous one.
  6. AC2: The search activity ID is reset when the search overlay is closed.
{
    "action": "click",
    "funnel_name": "Search related articles",
    "funnel_entry_token": "95fba955484638851a7dm6vk31xp",
    "experiments": {
        "enrolled": [
            "RelatedArticles test experiment betacluster\t"
        ],
        "assigned": {
            "RelatedArticles test experiment betacluster\t": "experimentEnabled"
        }
    },
    "action_source": "search_box",
    "$schema": "/analytics/product_metrics/web/base/1.3.0",
    "mediawiki": {
        "site_content_language": "en",
        "skin": "minerva"
    },
    "performer": {
        "session_id": "c35a51529d3c957f6006",
        "is_logged_in": true
    },
    "agent": {
        "client_platform": "mediawiki_js",
        "client_platform_family": "mobile_browser"
    },
    "sample": {
        "rate": 1,
        "unit": "session"
    },
    "dt": "2025-02-08T02:08:10.381Z",
    "meta": {
        "stream": "product_metrics.web_base.search_ab_test_clicks",
        "domain": "en.wikipedia.beta.wmflabs.org"
    }
}

Test Case 3: Verify search activity ID is included in all click tracking events

  1. Open the search overlay as in Test Case 1.
  2. Interact with search recommendations (e.g., click on a suggestion).
  3. Submit a search query.
  4. Observe the console logs for click tracking events.
  5. Verify that each event includes the search activity ID as funnel_entry_token.
  6. ✅ AC3: The search activity ID is included in all click tracking events.

Clicking a search suggestion

{
    "action": "click",
    "font": "1",
    "is_full_width": false,
    "is_page_preview_on": true,
    "is_pinned": false,
    "is_media_viewer_enabled": true,
    "is_dark_mode_prepared_by_os": true,
    "dark_mode_setting": "0",
    "is_dark_mode_on": false,
    "action_context": "stable,amc",
    "viewport_size_bucket": "1200px-2000px",
    "action_source": "relatedArticles.emptySearch",
    "is_temp": false,
    "$schema": "/analytics/mediawiki/product_metrics/web_ui_actions/1.0.2",
    "page": {
        "namespace_id": 0
    },
    "performer": {
        "is_logged_in": true,
        "session_id": "c35a51529d3c957f6006",
        "pageview_id": "eb8af1d462305bfd8c49",
        "edit_count_bucket": "5-99 edits",
        "groups": [
            "*",
            "user",
            "autoconfirmed"
        ],
        "is_bot": false
    },
    "mediawiki": {
        "skin": "minerva",
        "database": "enwiki"
    },
    "agent": {
        "client_platform": "mediawiki_js",
        "client_platform_family": "mobile_browser"
    },
    "sample": {
        "rate": 1,
        "unit": "session"
    },
    "dt": "2025-02-08T02:14:40.027Z",
    "meta": {
        "stream": "mediawiki.web_ui_actions",
        "domain": "en.wikipedia.beta.wmflabs.org"
    }
}

Typing into the search box

{
    "action": "type",
    "funnel_name": "Search related articles",
    "funnel_entry_token": "1316c1ed8ae8168a406cm6vkbcjc",
    "experiments": {
        "enrolled": [
            "RelatedArticles test experiment betacluster\t"
        ],
        "assigned": {
            "RelatedArticles test experiment betacluster\t": "experimentEnabled"
        }
    },
    "action_source": "search_box",
    "$schema": "/analytics/product_metrics/web/base/1.3.0",
    "mediawiki": {
        "site_content_language": "en",
        "skin": "minerva"
    },
    "performer": {
        "session_id": "c35a51529d3c957f6006",
        "is_logged_in": true
    },
    "agent": {
        "client_platform": "mediawiki_js",
        "client_platform_family": "mobile_browser"
    },
    "sample": {
        "rate": 1,
        "unit": "session"
    },
    "dt": "2025-02-08T02:16:33.273Z",
    "meta": {
        "stream": "product_metrics.web_base.search_ab_test_clicks",
        "domain": "en.wikipedia.beta.wmflabs.org"
    }
}

Test Case 4: Verify the same search activity ID is maintained within a single session

  1. Open the search overlay.
  2. Perform multiple actions without closing the overlay (e.g., type queries, click recommendations).
  3. Observe the console logs for click tracking events.
  4. Verify that all events share the same search activity ID.
  5. ✅ AC4: The same search activity ID is maintained during the session until the overlay is closed.

screenshot 183.png (147×1 px, 83 KB)

Change #1118558 had a related patch set uploaded (by Jdlrobson; author: Bernard Wang):

[mediawiki/extensions/WikimediaEvents@wmf/1.44.0-wmf.15] Add search activity id

https://gerrit.wikimedia.org/r/1118558

Edtadros subscribed.
Jdlrobson-WMF claimed this task.

Change #1118558 merged by jenkins-bot:

[mediawiki/extensions/WikimediaEvents@wmf/1.44.0-wmf.15] Add search activity id

https://gerrit.wikimedia.org/r/1118558

Mentioned in SAL (#wikimedia-operations) [2025-02-11T22:16:49Z] <jdrewniak@deploy2002> Started scap sync-world: Backport for [[gerrit:1118873|Fixes: Selecting search results on mobile website in Firefox does not work (T381289)]], [[gerrit:1118841|Fixes: Selecting search results on mobile website in Firefox does not work (T381289)]], [[gerrit:1118558|Add search activity id (T383936)]]

Mentioned in SAL (#wikimedia-operations) [2025-02-11T22:19:52Z] <jdrewniak@deploy2002> jdlrobson, jdrewniak: Backport for [[gerrit:1118873|Fixes: Selecting search results on mobile website in Firefox does not work (T381289)]], [[gerrit:1118841|Fixes: Selecting search results on mobile website in Firefox does not work (T381289)]], [[gerrit:1118558|Add search activity id (T383936)]] synced to the testservers (https://wikitech.wikimedia.org/wiki/Mwdebug)

Mentioned in SAL (#wikimedia-operations) [2025-02-11T22:30:04Z] <jdrewniak@deploy2002> Finished scap sync-world: Backport for [[gerrit:1118873|Fixes: Selecting search results on mobile website in Firefox does not work (T381289)]], [[gerrit:1118841|Fixes: Selecting search results on mobile website in Firefox does not work (T381289)]], [[gerrit:1118558|Add search activity id (T383936)]] (duration: 13m 14s)

Status: ❓ need more info
Environment: cawiki
OS: macOS
Browser: Chrome
Device: MS

Test Case 1: Verify unique search activity ID is generated when search overlay opens

  1. Open an incognito window and visit https://ca.m.wikipedia.org/wiki/Dog_(cinologia)
  2. Open the browser console and execute:
mw.loader.using('mediawiki.api').then(function () {  
  new mw.Api().saveOption('eventlogging-display-console', '1');  
});
  1. Click on the search box to open the search overlay.
  2. Observe the console logs for click tracking events.
  3. Verify that a unique search activity ID is generated and included as funnel_entry_token.
  4. AC1: A unique search activity ID is generated when the search overlay opens.

The only thing that could be a unique search activity ID appears to be the web_session_id

screenshot 36.png (230×529 px, 39 KB)

Test Case 2: Verify search activity ID is reset when search overlay closes

  1. Follow Test Case 1 to open the search overlay and generate an ID.
  2. Close the search overlay.
  3. Reopen the search overlay.
  4. Observe the console logs for new events.
  5. Verify that a new search activity ID is generated, different from the previous one.
  6. AC2: The search activity ID is reset when the search overlay is closed.

nothing changes when the overlay is closed. This may be an out of date requirement.

Test Case 3: Verify search activity ID is included in all click tracking events

  1. Open the search overlay as in Test Case 1.
  2. Interact with search recommendations (e.g., click on a suggestion).
  3. Submit a search query.
  4. Observe the console logs for click tracking events.
  5. Verify that each event includes the search activity ID as funnel_entry_token.
  6. ❓AC3: The search activity ID is included in all click tracking events.

If it is the web_session_id then it is included. Here is a screengrab showing the events from opening the page, clicking search, clicking one of the search recommendations, clicking a footer recommendation

screenshot 37.png (236×1 px, 110 KB)

Test Case 4: Verify the same search activity ID is maintained within a single session

  1. Open the search overlay.
  2. Perform multiple actions without closing the overlay (e.g., type queries, click recommendations).
  3. Observe the console logs for click tracking events.
  4. Verify that all events share the same search activity ID.
  5. ❓ AC4: The same search activity ID is maintained during the session until the overlay is closed.

See above. However, in beta there was a funnel_entry_token, but I don't see one in Prod.

Does the following clarify things? FWIW I seem to be able to confirm all of these steps:

❓AC1: A unique search activity ID is generated when the search overlay opens.

We are looking for funnel_entry_token

❓ AC2: The search activity ID is reset when the search overlay is closed.

nothing changes when the overlay is closed. This may be an out of date requirement.

The event fires when the overlay is reopened. Specifically we want to check the new click event with event_source search_box' has a different funnel_entry_token from previous ones. That appears to be working.

Chatted with @Edtadros synchronously today. He will update this ticket.