Expand my Community achievements bar.

SOLVED

how does count number of words used in search term

Avatar

Level 1

Hi Team,

I am using evar1 to capture the search term , client wants to know how many words are used in search term.

Is there way in adobe analytics workspace if calculated metrics with any functions will achieve this ask. 

Or we need to ask the developer to pass the count of words in another evars.

1 Accepted Solution

Avatar

Correct answer by
Level 9

Hi @AnkitGa2 ,

I confused number of words with number of characters, above solution is for counting characters. For counting words you can apply the same logic but with different regex like below,

Harveer_SinghGi1_1-1739631144055.png

and ruleset test results also validate it,

Harveer_SinghGi1_0-1739630999913.png

Also, I agree with @bjoern__koth , you don't need developer's help to start collecting this information client side, you can handle this in Adobe Launch using JS split and length methods. Adobe Launch JS implementation should be considered as a permanent solution while you can consider rule builder to work with upto 6 months historical data.

Cheers!

View solution in original post

6 Replies

Avatar

Level 9

Hi @AnkitGa2 ,

AA calculated metrics can't be used to count the characters in a dimension value, it will be best to work with your developers to pass this information while data collection only. 

If you want to achieve this in AA UI only and don't want to got the development route, you should be able to achieve this using classification rule builder with some tradeoff off course. Here's my proposed, you setup the rule builder to check different string lengths using regex and on a match return the tested length in classification report as below,

Harveer_SinghGi1_0-1739611725650.png

Here's the ruleset test showing this logic work,

Harveer_SinghGi1_1-1739611787234.png

The tradeoff that I mentioned before comes in the decision of how far you want to go for checking specific lengths. In my example above I'm marking everything with more than 5 characters as "5+", you may want to add more rules to check individual lengths upto 10 characters and mark everything else as "10+" or go to "20+", "30+" maybe. The point is you may not be able to account for all unique lengths (unless you have a length constraint of your search term) and you'll have to put a sort of catch all rule after a certain length.

Hope this is helpful for your use case!

Cheers!

Avatar

Correct answer by
Level 9

Hi @AnkitGa2 ,

I confused number of words with number of characters, above solution is for counting characters. For counting words you can apply the same logic but with different regex like below,

Harveer_SinghGi1_1-1739631144055.png

and ruleset test results also validate it,

Harveer_SinghGi1_0-1739630999913.png

Also, I agree with @bjoern__koth , you don't need developer's help to start collecting this information client side, you can handle this in Adobe Launch using JS split and length methods. Adobe Launch JS implementation should be considered as a permanent solution while you can consider rule builder to work with upto 6 months historical data.

Cheers!

Avatar

Level 2

You can definitely use a calculated metric in Adobe Analytics to count the number of words in a search term. You can use a combination of the length and split functions to count spaces or split the string by spaces and get the word count. No need for a developer to pass it separately if you're comfortable with calculated metrics!

Avatar

Community Advisor

If you're using Datastreams and Web SDK, this should also be possible through data prep functions.

 

Else, @Harveer_SinghGi1 's approach is straight forward.

 

Alternatively, this could also easily be done in Launch using a cUstinov code data element that uses split and length


simplified

 

"  foo     bar   hello  world    ".trim().replaceAll(/\s+/g, " ").split(" ").length

 

  • removing whitespace at the beginning and end
  • replacing multiple succeeding whitespaces with a single space

For completenes, using the AEP data prep functions for an automatic mapping, it could look somewhat like this

 

Dummy JSON

bjoern__koth_0-1739778165000.png

 

Mapping functions applied for a calculated field

bjoern__koth_1-1739778217808.png

 

@AnkitGa2 I am sure you find an approach that works for you

 

 

Cheers from Switzerland!


Avatar

Community Advisor and Adobe Champion

I agree with the others here, if you need to get historical data (or just don't want to use up another dimension, then using classifications and regex can be used to get your word count  (with the exception of the last item being a catchall for 5+ or 6+ etc words).

 

If you need to track the specific word count, then you should be able to create logic in Adobe Launch to determine the word count and pass that value into your tracking. And as @bjoern__koth mentioned, you might want to get a little more advanced to try and avoid multiple spaces in a row as counting as words, also spaces at the beginning or end of the string can be trimmed to avoid those from impacting your word count.

 

As already mentioned, there are potentially multiple approaches to this, it comes down to what works best for you.

Avatar

Level 1

Hi @AnkitGa2 If you are using adobe Launch custom JS, then you can do the same using a custom rule in launch

 var searchTerm = _satellite.getVar('search term');

var wordCount = searchTerm ? searchterm.trim() .split(/\s+). length : 0;

s.eVar1= wordCount;

Based on your setup and requirement, you can go with classification, processing rule or launch/tealium intergeration