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 getQueryParam
plug-in allows you to extract the value of any query string parameter contained in a URL. It is useful for extracting campaign codes, both internal and external, from landing page URLs. It is also valuable when extracting search terms or other query string parameters.
This plug-in provides robust features in parsing complex URLs, including hashes and URLs containing multiple query string parameters. If you only have simple query string parameter needs, Adobe recommends using the URL parameter features in Launch or the Util.getQueryParam()
method included in AppMeasurement.
Adobe offers an extension that allows you to use most commonly-used plug-ins.
If you do not want to use the plug-in extension, you can use the custom code editor.
/******************************************* BEGIN CODE TO DEPLOY *******************************************/
/* Adobe Consulting Plugin: getQueryParam v3.3 (Requires pt plug-in) */
s.getQueryParam=function(qsp,de,url){var g=this,e="",k=function(b,de){de=de.split("?").join("&");de=de.split("#").join("&");var d=de.indexOf("&"),url="";b&&(-1<d||de.indexOf("=")>d)&&(d=de.substring(d+1),url=g.pt(d,"&","gpval",b));return url};qsp=qsp.split(",");var l=qsp.length;g.gpval=function(de,b){if(de){var d=de.split("="),url=d[0];d=d[1]?d[1]:!0;if(b.toLowerCase() ==url.toLowerCase())return"boolean"===typeof d?d:this.unescape(d)}return""};de=de?de:"";url=(url?url:g.pageURL?g.pageURL: location.href)+"";if((4<de.length||-1<de.indexOf("="))&&url&&4>url.length){var b=de;de=url;url=b}for(var h=0;h<l;h++)b=k(qsp[h],url) ,"string"===typeof b?(b=-1<b.indexOf("#")?b.substring(0,b.indexOf("#")):b,e+=e?de+b:b):e=""===e?b:e+(de+b);return e};
/* Adobe Consulting Plugin: pt v2.01 */
s.pt=function(l,de,cf,fa){if(l&&this[cf]){l=l.split(de||",");de=l.length;for(var e,c=0;c<de;c++)if(e=this[cf](l[c],fa))return e}};
/******************************************** END CODE TO DEPLOY ********************************************/
The getQueryParam
method uses the following arguments:
qsp
(required): A comma delimited list of query string parameters to look for within the URL. It is not case-sensitive.de
(optional): The delimiter to use if multiple query string parameters match. Defaults to an empty string.url
(optional): A custom URL, string, or variable to extract the query string parameter values from. Defaults to window.location
.Calling this method returns a value depending on the above arguments and the URL:
true
.de
argument.If the current URL is the following:
http://www.abc123.com/?cid=trackingcode1
The following code will set s.campaign equal to “trackingcode1”:
s.campaign=s.getQueryParam('cid');
If the current URL is the following:
http://www.abc123.com/?cid=trackingcode1&ecid=123456
The following code will set s.campaign equal to “trackingcode1:123456”:
s.campaign=s.getQueryParam('cid,ecid',':');
If the current URL is the following:
http://www.abc123.com/?cid=trackingcode1&ecid=123456
The following code will set s.campaign equal to “trackingcode1123456”:
s.campaign=s.getQueryParam('cid,ecid');
If the current URL is the following:
http://www.abc123.com/?cid=trackingcode1&ecid=123456#location
The following code will set s.campaign equal to “123456”:
s.campaign=s.getQueryParam('ecid');
If the current URL is the following:
http://www.abc123.com/#location&cid=trackingcode1&ecid=123456
The following code will set s.campaign equal to “123456”
s.campaign=s.getQueryParam('ecid');
Note: The plug-in replaces the URL to Check’s hash character with a question mark if a question mark does not exist. If the URL contains a question mark that comes before the hash character, the plug-in will replace the URL to Check’s hash character with an ampersand;
If the current URL is the following…
http://www.abc123.com/
…and if the variable s.testURL is set as follows:
s.testURL="http://www.abc123.com/?cid=trackingcode1&ecid=123456#location&pos=300";
The following code will not set s.campaign at all:
s.campaign=s.getQueryParam('cid');
However, the following code will set s.campaign equal to “trackingcode1”:
s.campaign=s.getQueryParam('cid','',s.testURL);
Note: the third parameter can be any string/variable that the code will use to try to find the query string parameters in
The following code will set s.eVar2 equal to “123456|trackingcode1|true|300”:
s.eVar2=s.getQueryParam('ecid,cid,location,pos','|',s.testURL);
The value of 300 comes from the value of the pos parameter in the s.testURL variable
findParameterValue
and getParameterValue
functions into the getQueryParam
functionfindParameterValue
and getParameterValue
for readability purposes.s.pt
with AppMeasurement).h
parameter, allowing the code to find query string parameters found after the hash (#
) character