Adobe plug-in: inList
The inList
plug-in allows you to check if a value already exists within either a delimited string or a JavaScript array object. Several other plug-ins depend on the inList
plug-in to work. This plug-in provides a distinct advantage over the JavaScript method indexOf()
where you it does not match partial strings. For example, if you used this plug-in to check for "event2"
, it won’t match with a string containing "event25"
. This plug-in is not necessary if you don’t need to check for values in delimited strings or arrays, or if you want to use your own indexOf()
logic.
Install the plug-in using the Web SDK or Web SDK extension
This plug-in is not yet supported for use within the Web SDK.
Install the plug-in using the Adobe Analytics extension
Adobe offers an extension that allows you to use most commonly-used plug-ins with Adobe Analytics.
-
Log in to Adobe Experience Platform Data Collection using your AdobeID credentials.
-
Click the desired tag property.
-
Go to the Extensions tab, then click on the Catalog button
-
Install and publish the Common Analytics Plugins extension
-
If you haven’t already, create a rule labeled “Initialize Plug-ins” with the following configuration:
- Condition: None
- Event: Core – Library Loaded (Page Top)
-
Add an action to the above rule with the following configuration:
- Extension: Common Analytics Plugins
- Action Type: Initialize inList
-
Save and publish the changes to the rule.
Install the plug-in using custom code editor
If you do not want to use the Common Analytics Plugins plug-in extension, you can use the custom code editor.
- Log in to Adobe Experience Platform Data Collection using your AdobeID credentials.
- Click on the desired property.
- Go to the Extensions tab, then click the Configure button under the Adobe Analytics extension.
- Expand the Configure tracking using custom code accordion, which reveals the Open Editor button.
- Open the custom code editor and paste the plug-in code provided below into the edit window.
- 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: inList v3.0 */
function inList(lv,vtc,d,cc){var b=lv,e=vtc,c=d,f=cc;if("-v"===b)return{plugin:"inList",version:"3.0"};a:{if("undefined"!==typeof window.s_c_il){var a=0;for(var d;a<window.s_c_il.length;a++)if(d=window.s_c_il[a],d._c&&"s_c"===d._c){a=d;break a}}a=void 0}"undefined"!==typeof a&&(a.contextData.inList="3.0");if("string"!==typeof e)return!1;if("string"===typeof b)b=b.split(c||",");else if("object"!==typeof b)return!1;c=0;for(a=b.length;c<a;c++)if(1==f&&e===b[c]||e.toLowerCase()===b[c].toLowerCase())return!0;return!1};
/******************************************** END CODE TO DEPLOY ********************************************/
Use the plug-in
The inList
function returns a boolean depending on its inputs. It uses the following arguments:
lv
(required, string or array): A delimited list of values or a JavaScript array object to searchvtc
(required, string): The value to search ford
(optional, string): The delimiter used to separate individual values in thelv
argument. Defaults to a comma (,
) when not set.cc
(optional, boolean): If set totrue
or1
, a case-sensitive check is made. If set tofalse
or omitted, then a case-insensitive check is made. Defaults tofalse
.
Calling this function returns true
if it finds a match, and false
if it does not find a match.
Examples
// Returns true
s.events = "event22,event24";
if(inList(s.events,"event22")) {
// Code will execute
}
// Returns false because event2 is not an exact match in the string
s.events = "event22,event24";
if(inList(s.events,"event2")) {
// Code will not execute
}
// Returns true because of the NOT operator
s.events = "event22,event24";
if(!inList(s.events,"event23")) {
// Code will execute
}
// Returns false because of the case-sensitive check
s.events = "event22,event23";
if(inList(s.events,"EVenT23","",true)) {
// Code will not execute
}
// Returns false because of a mismatched delimiter, treating "events,eVar1" as a single value
s.linkTrackVars = "events,eVar1";
if(inList(s.linkTrackVars,"eVar1","|")) {
// Code will not execute
}
Version History
3.0 (March 19, 2021)
- Added version number as context data.
v2.1 (September 26, 2019)
- Added the option for the
cc
argument to not be a boolean. For example,1
is a valid case check value.
v2.0 (April 17, 2018)
- Point release (recompiled, smaller code size).
v1.01 (September 27, 2017)
- Optimized code to reduce size
v1.0 (2009)
- Initial release.