Making WordPress.org

Opened 5 years ago

Closed 5 years ago

Last modified 5 years ago

#5157 closed defect (bug) (fixed)

Update URL on search actions

Reported by: jonoaldersonwp's profile jonoaldersonwp Owned by:
Milestone: Priority: normal
Component: General Keywords: analytics
Cc:

Description (last modified by jonoaldersonwp)

Our site search tracking is currently severely limited due to the way in which the search has been implemented. Whilst there are some workarounds we can utilise in Google Tag Manager, we need to make some minor alterations to the functionality in order close some gaps.

On a generic search results page like https://wordpress.org/search/cats, the URL should be updated (via the history API) when the query is altered and the form submitted.

E.g., changing the value of 'cats' to 'dogs' and either clicking the 'submit' button or pressing enter should alter the URL to https://wordpress.org/search/dogs.

Additionally, the (lowercased) text value of the 'category' label should be appended to the URL via a search_category parameter (replacing spaces with underscores) when the category of results is altered (e.g., selecting "Support Docs"). E.g.:

https://wordpress.org/search/dogs?search_category=all
https://wordpress.org/search/dogs?search_category=support_forums
https://wordpress.org/search/dogs?search_category=support_docs
https://wordpress.org/search/dogs?search_category=developer_documentation

Note that none of this applies to plugin/theme search templates, which work differently.

Change History (11)

#1 @jonoaldersonwp
5 years ago

  • Description modified (diff)

#2 @jonoaldersonwp
5 years ago

  • Description modified (diff)

#3 @jonoaldersonwp
5 years ago

  • Description modified (diff)

#4 @jonoaldersonwp
5 years ago

  • Description modified (diff)

This ticket was mentioned in Slack in #docs by jonoaldersonwp. View the logs.


5 years ago

#6 @dd32
5 years ago

  • Resolution set to fixed
  • Status changed from new to closed

#7 @jonoaldersonwp
5 years ago

  • Priority changed from normal to highest omg bbq

It seems that navigating between categories has now breaks category-based search(!); submitting a query returns you to the previously selected category.

Three other challenges to address, though, before this is viable for GTM/GA:

  • It looks like the URL is updated after the form result is returned. That means it's too late for GTM to pick up the change easily. It needs to change on click/submit.
  • Navigation between categories which have previously been selected doesn't update the URL.

#8 @dd32
5 years ago

  • Priority changed from highest omg bbq to normal

It looks like the URL is updated after the form result is returned. That means it's too late for GTM to pick up the change easily. It needs to change on click/submit.

Unfortunately that's because Google custom search doesn't appear to offer any signal as to what section is selected. It can only be determined after render.

The category parameters aren't as per the requirements (e.g., https://wordpress.org/search/dogs?forums=1 should be https://wordpress.org/search/dogs?search_category=support_forums).

Correct, They use our existing search format. I'm not changing that.

Navigation between categories which have previously been selected doesn't update the URL.

It does, if the search refreshes. Unfortunately Google Custom Search doesn't have a callback to trigger on after the results are already cached in the DOM.

Version 0, edited 5 years ago by dd32 (next)

#9 @jonoaldersonwp
5 years ago

I was assuming we'd use some JS just to sniff for interactions, and implement it that way. The current approach doesn't solve the problem.

If we're going to address this, then it needs to be as per the brief. Otherwise, we should revert; with the implication that we'll write-off ever having any useable search analytics. Or, I'll have to build some over-engineered JS in GTM, which is far from ideal.

#10 @dd32
5 years ago

Can you explain the issues with the implementation? Just saying it must be "per ticket" doesn't help.

#11 @jonoaldersonwp
5 years ago

As per the spec, and my feedback:

  • We need to trigger URL updates when the query is altered / when the form is submitted; not after the response is processed and the results updated.
  • We need a consistent key for the search category (preferably 'search_category').
  • We need subsequent/repeated navigation actions to also trigger a URL update.
Note: See TracTickets for help on using tickets.