Implement internal search variables using AppMeasurement

Last update: 2023-05-31
  • Created for:
  • Intermediate

In this video, we go through the steps of implementing internal site search variables for Adobe Analytics using Experience Platform Launch, including search term, number of results, and others.


Hey everybody, it’s Doug. In this video, I want to show you how to implement internal search variables when you’re using App Measurement and you’re using Experience Platform Launch. And I’m going to start here in the Business Requirements Document the BRD, and we have defined what we want to track. And I’ve got these items up here that we’re going to start with. We want to track these things for sure. And then we can track some other things if we want to too. Once we know how to do these up here then the rest of these are easy. You just put them in additional eVars or trigger additional events, et cetera. So, we’re just going to do a few of these things up here, and then you can use that method to add additional values down here. So once you’ve got the business requirements documented here, step one is really to go into this variable map or go into your Solution Design, your SDR and start documenting exactly how you are going to implement those. So, you can see here that, for example, for eVar10 since that’s going to be our search term I would put that here. I can then put for example where are you going to get the data from what variable on the page, et cetera, the name of the data element you’re going to put it into in Launch and the rule you’re going to use in Launch to set variables and or send the data into analytics. So again, yeah, fill those out for everything you’re going to track. Let me just click back over to the requirements and let’s take a look and launch to see how we can actually implement these items up here.

So here in Launch, I’m in the data elements section and that’s the next step is to get your variable values into data elements. So, in addition to the page name that was already here you can see that I’m adding the search term, the number of results and any filters that have been chosen into these data elements. So again, you’re going to need to know where am I getting the search term from? Is it in a variable on my page? Is it in a Query string on the URL? Where am I going to get it? So if search is already implemented on your site then certainly it is somewhere and you just need to talk to somebody and find out where the search term is available. Then you can create this data element. So, I already did the add data element and I’ll click into search term here. And for this demo, I have it actually being pulled from the query string parameter of q. But it’s also very possible that you’re going to grab it from a JavaScript variable, for example, on your page. But you know maybe you just need some custom code to do something with it. Maybe it’s a DOM Attribute, maybe it’s wherever, right? You’re going to be able to grab this search term from somewhere on your page. And again, if it’s in the JavaScript variable then maybe it is part of your data layer. So, for example, maybe it’s in digital data.pagesearch.term or something like that, right? So wherever it is on your page or in your data layer you can call it from there. Again, you can do like I did before and have a Query String Parameter in this case I’m choosing q and we’re calling it good. Now let me cancel out of that.

And you’re basically doing the same thing for the number of search results. Where are you giving the number of search results from on your page? For this demo you’ll see that I’m actually going to pull that also from a Query String Parameter called Results. Cancel all of that. And for the filters that have been chosen I’m going to grab that from filters as well. Now I will just say here if you’re going to put multiple things in the filters data element, then have you concatenated all of the chosen filters into one say comma separated value and put that into your data layer. Or do you need to use something like if I click on this maybe some custom code to go look at different variables on your page and concatenate them here and make one value here. So however you want to do that I’m going to assume here that it’s already been done and then we’re just going to pull that from in this case, the Query String Parameter but you would pull that maybe from your JavaScript variable and put that into this data element. So, I’m going to cancel out of that one and now you’ve got the values in the data elements. Now we need to use them. So, we jump over to rules. Now I’m going to assume that you already have a default page load rule and we’re just going to talk about these internal search rules here. Now I’m setting those to execute before my default page load rule, 'cause my default page load rule has the send beacon activity. And so, I don’t need to put a send beacon on these other ones because they’ll execute first and then the default page load rule will send them in. So, click into my internal search DOM Ready 50 and you can see this is going to execute just when it’s done ready. I don’t need to click into that but basically the condition is whenever there is a Query String Parameter of q and as you can see here with red jacks when there’s anything in it, right. .plus, so one or more characters of anything in the q parameter in the query string, okay. So that’s when it’s going to execute. So, cancel all of that. And what is it going to do when there is something in the q parameter in the query string? Well, it’s going to set some variables and this is when we jumped back to our Business Requirements Document and I want to set the internal search term. I want to set that there was a search eVar4 I want to track the number of search results returned. And if there are any filters I’ll come back for the bad searches in a minute but we definitely want to track eVar10, eVar11 set eVar4 because there was a search and then also List Var 1 because we might have several values in the filters variable. So yeah, eVar10 and 11, eVar 4, Lists Var 1. So, we go back and when this runs again eVar10 gets set to the search terms. So, I click on this right here, and this is where we pull the data element from the search term right there. So, I’ve already selected that.

We’re going to set eVar11 the same way, set that from the number of search results, right? So I just selected the data element number of search results. And then I triggered event four, which is what I set aside for yes, there was a search. Now you can see there’s no List Var here. There’s no spot for that. So, we’re actually going to use some custom code because once again, if we go back over we want to set the filters into List Var 1.

So, we go to open our editor and we basically just look at the filters data element by using _satellite.getVar. And we put it into S.List1.

So, List var 1, okay. So let me cancel out that. So that all runs when there is a search when that q parameter has something in it. Let me cancel all of that and cancel out of that one. And then I have a zero results search as well. So, if there are no results then we’re going to set this variable to zero. So, you’re going to have to talk to your web developers and have them set it to zero or whether that’s the string zero or just a zero number or however they’re going to do it. But for this example, if I click in here, you’ll see again this is just running on DOM Ready? And it’s saying, yes when there’s something in the q parameter like before and if I click into this one, the number of search results has zero, the word zero in it. So again, you’d have to see what on your site is happening when there are zero search results. And you could use something like this as the condition type of value comparison. And so, I’m just saying, you know if this is set to this word zero then it means there were no search results. Then that means it can run this one down here. So, this action is to set variables for analytics and we are setting event five. Like we defined over here, even five in an unsuccessful search or a bad search or what are you going to call it. So again, those will run when those items have been found true, right a Query String Parameter q and it matches zero results. So, let’s take a look at an example and I’m actually going to go over to the site here and I’ve got my debugger here and ready to go. And so, if I click back and again remember I kind of had everything in a query parameter so it would be easy to test here. I’ve got my q value. So, it is searching for the word pants and results equals zero. Actually, let’s do this first time. Let’s say five results happened from searching for pants and that the filters chosen where just some random value here zzz. So, when I run this and say, reload that, oh and that reload at zero, that’s fine. Let’s look at that one first. So, we can go into our debugger here and we can see as we scroll down that eVar10 was pants, right? That is a search term. eVar11 is the number of search results, which is zero. And because there were zero search results not only we did, we have an event four which is for any search, but we had also an event five which was a zero results search. So, if we change the results, for example if I try that again and hit five then enter and go back to our debugger, then you can see that again we searched for pants. That time we had five results. And so, we only had event four, which is any search. Did not have event five this time because there were actual results. Anyway, I know that was a bit lengthy but I hope that helped to walk through some of the steps in Launch to track internal search. Good luck. -

On this page