So you can pass a custom event triggered on a page load to include inSidedData.search.module as one of the event parameters. You’ll also be able to then groupBy that parameter in query builder to aggregate events by module.
Thanks @rschlette
This also answered another question i had from my knowledge manager about search terms, so this is awesome.
I am struggling though to get the actual search phrase into a variable.
I added the console log to print into the screen so i can see if the variable is being picked up, which it is not.
Can you help me clean it up?
Sure thing. I’m making the assumption that you want to send an event to PX when the search results page loads. If that’s not right, let me know the event trigger.
For search query and result count on page load, I’d use something like this:
// Check for 'search' query parameter on page load window.addEventListener('DOMContentLoaded', () => { const urlParams = new URLSearchParams(window.location.search); const searchParam = urlParams.get('search');
if (searchParam !== null && searchParam.trim() !== '') { // Send search data to PX query = inSidedData.search.phrase; results = inSidedData.search.count; aptrinsic('track', 'CC Search', { "query": query, "resultCount": results }); // test point console.log(results+' results for search term(s): ' + query); } });
So the workflow is:
page load
check for the presence of the ‘search’ query param (to indicate that this is a search result page)
grab the search query and result count from inSidedData
send the above to PX in a custom event
optional console test point for easy debugging
You can refine that conditional statement all sorts of ways, but in this case the event fires anytime a page loads with an active search param value. Let me know if you run into any issues using that. My current employer isn’t a CC customer, so I don’t have a great test environment anymore, but I’m happy to help.
@rschlette
I have copied and pasted the code above into INSERT BEFORE </BODY> TAG within Control.
I do not get any event in PX, nor does the test point.
as you can see here it is in the source code.
the custom event is not being sent, the console is not printing. any thoughts?
Thanks in advance
I see one thing. In the line where we define searchParam, I was using the parameter name ‘search’ when it appears that the live CC site uses ‘q’
so the line that reads:
const searchParam = urlParams.get('search');
should read:
const searchParam = urlParams.get('q');
That one works using Tamper Monkey on this site, so hopefully it will work on your site as well.
One additional note, I’m not sure on that site whether you can have the script load at the end of the body element and use the DOMContentLoaded event effectively. You might try moving this script to the top of the body element so that the event listener is loaded before the DOMContentLoaded event fires.
If you ever had a profile with us, there's no need to create another one. Don't worry if your email address has since changed, or you can't remember your login, just let us know at community@gainsight.com and we'll help you get started from where you left.
Else, please continue with the registration below.