Adobe plug-in: cleanStr

IMPORTANT

This plug-in is provided by Adobe Consulting as a courtesy to help you get more value out of Adobe Analytics. Adobe Customer Care does not provide support with this plug-in, including installation or troubleshooting. If you require help with this plug-in, contact your organization’s Account Manager. They can arrange a meeting with a consultant for assistance.

The cleanStr plug-in removes or replaces all unnecessary characters from a string, including HTML tag characters, extra whitespaces, tabs, and newline/carriage returns. It also replaces left/right single quotes ( and ) with straight single quotes ('). Adobe recommends using this plug-in if you want to remove unnecessary characters from variable values and the ‘Clean text’ feature in Launch does not fulfill your implementation needs. This plug-in is not necessary if the collected data does not contain unnecessary characters, or if the ‘Clean text’ feature in Launch is sufficient.

Install the plug-in using the Adobe Experience Platform Launch extension

Adobe offers an extension that allows you to use most commonly-used plug-ins.

  1. Log in to launch.adobe.com using your AdobeID credentials.
  2. Click the desired property.
  3. Go to the Extensions tab, then click on the Catalog button
  4. Install and publish the Common Analytics Plugins extension
  5. If you haven’t already, create a rule labeled “Initialize Plug-ins” with the following configuration:
    • Condition: None
    • Event: Core – Library Loaded (Page Top)
  6. Add an action to the above rule with the following configuration:
    • Extension: Common Analytics Plugins
    • Action Type: Initialize cleanStr
  7. Save and publish the changes to the rule.

Install the plug-in using Launch custom code editor

If you do not want to use the plug-in extension, you can use the custom code editor.

  1. Log in to launch.adobe.com using your AdobeID credentials.
  2. Click on the desired property.
  3. Go to the Extensions tab, then click the Configure button under the Adobe Analytics extension.
  4. Expand the Configure tracking using custom code accordion, which reveals the Open Editor button.
  5. Open the custom code editor and paste the plug-in code provided below into the edit window.
  6. Save and publish the changes to the Analytics extension.

Install the plug-in using AppMeasurement

Copy and paste the following code anywhere in the AppMeasurement file after the Analytics tracking object is instantiated (using s_gi). Preserving comments and version numbers of the code in your implementation helps Adobe with troubleshooting any potential issues.

/******************************************* BEGIN CODE TO DEPLOY *******************************************/
/* Adobe Consulting Plugin: cleanStr v1.0 */
function cleanStr(str){if("string"===typeof str){str=str.replace(/<\/?[^>]+(>|$)/g,"");str=str.trim(); str=str.replace(/[\u2018\u2019\u201A]/g,"'");str=str.replace(/\t+/g,"");for(str=str.replace(/[\n\r]/g," ");-1<str.indexOf("  ");)str=str.replace(/\s\s/g," ");return str}return""};
/******************************************** END CODE TO DEPLOY ********************************************/

Use the plug-in

The cleanStr method uses the following arguments:

  • str (required, string): The value that you want to clean HTML encoding, extra whitespace, tabs, or other unnecessary characters.

The method returns the value of the str argument with all unnecessary characters removed.

Examples

Example #1

Assume the following (where the dots represent spaces and the arrows represent tab characters

s.eVar1 = "»∙∙this∙∙is∙a∙∙»∙messy»string∙∙∙∙"

When you run the following code…

s.eVar1 = cleanStr(s.eVar1)

…eVar1 will be set equal to “this is a messystring” (with all extra spaces and all tab characters removed)

Example #2

If…

s.eVar1 = "»∙∙this∙∙is∙a∙∙»∙messy»string∙∙∙∙"

…and the following code runs…

cleanStr(s.eVar1)

…the final value of s.eVar1 will still be:

"»∙∙this∙∙is∙a∙∙»∙messy»string∙∙∙∙"

Running the plug-in all by itself (without assigning the return value to a variable) does not actually “reset” the variable passed in through the str argument.

Version History

1.0 (April 15, 2018)

  • Initial release.

On this page