此插件由 Adobe Consulting 团队提供,旨在帮助您从 Adobe Analytics 中获取更多的价值。Adobe 客户关怀团队不提供对此插件的支持,包括安装或疑难解答。如果您需要关于此插件的帮助,请与您组织的 Adobe 客户团队联系。他们可为您安排与顾问会面以寻求帮助。
getQueryParam
插件允许您提取 URL 中包含的任意查询字符串参数的值。在从登录页面 URL 中提取内部和外部促销活动代码时,此插件非常有用。在提取搜索词或其他查询字符串参数时,此插件也非常有价值。
此插件在解析复杂 URL(包括散列和包含多个查询字符串参数的 URL)方面提供了强大的功能。如果您只需要使用简单的查询字符串参数,则Adobe建议您使用URL参数功能,该功能应当包括Web SDK或Adobe Analytics扩展,或者 Util.getQueryParam()
方法。
Adobe提供了一个扩展,允许您将最常用的插件与Web SDK结合使用。
getQueryParam
尚不支持在Web SDK的手动实施中使用此插件。
Adobe提供了一个扩展,允许您将最常用的插件与Adobe Analytics一起使用。
如果您不想使用“常用Analytics插件”插件扩展,则可以使用自定义代码编辑器。
/******************************************* BEGIN CODE TO DEPLOY *******************************************/
/* Adobe Consulting Plugin: getQueryParam v4.0.1 */
function getQueryParam(a,d,f){function n(g,c){c=c.split("?").join("&");c=c.split("#").join("&");var e=c.indexOf("&");if(g&&(-1<e||c.indexOf("=")>e)){e=c.substring(e+1);e=e.split("&");for(var h=0,p=e.length;h<p;h++){var l=e[h].split("="),q=l[1];if(l[0].toLowerCase()===g.toLowerCase())return decodeURIComponent(q||!0)}}return""}if("-v"===a)return{plugin:"getQueryParam",version:"4.0.1"};var b=function(){if("undefined"!==typeof window.s_c_il)for(var g=0,c;g<window.s_c_il.length;g++)if(c=window.s_c_il[g],c._c&&"s_c"===c._c)return c}();"undefined"!==typeof b&&(b.contextData.getQueryParam="4.0");if(a){d=d||"";f=(f||"undefined"!==typeof b&&b.pageURL||location.href)+"";(4<d.length||-1<d.indexOf("="))&&f&&4>f.length&&(b=d,d=f,f=b);b="";for(var m=a.split(","),r=m.length,k=0;k<r;k++)a=n(m[k],f),"string"===typeof a?(a=-1<a.indexOf("#")?a.substring(0,a.indexOf("#")):a,b+=b?d+a:a):b=""===b?a:b+(d+a);return b}};
/******************************************** END CODE TO DEPLOY ********************************************/
getQueryParam
函数使用以下参数:
qsp
(必需):包含要在 URL 中查找的查询字符串参数列表,以逗号分隔。此列表不区分大小写。de
(可选):当有多个匹配的查询字符串参数时使用的分隔符。默认使用空字符串。url
(可选):要从中提取查询字符串参数值的自定义 URL、字符串或变量。默认值为 window.location
。调用此函数时,会根据上述参数和 URL 返回一个值:
true
。de
参数中的字符串分隔。// Given the URL https://example.com/?cid=trackingcode
// Sets the campaign variable to "trackingcode"
s.campaign = getQueryParam('cid');
// Given the URL https://example.com/?cid=trackingcode&ecid=123
// Sets the campaign variable to "trackingcode:123"
s.campaign = getQueryParam('cid,ecid',':');
// Given the URL https://example.com/?cid=trackingcode&ecid=123
// Sets the campaign variable to "trackingcode123"
s.campaign = getQueryParam('cid,ecid');
// Given the URL https://example.com/?cid=trackingcode&ecid=123#location
// Sets the campaign variable to "123"
s.campaign = getQueryParam('ecid');
// Given the URL https://example.com/#location&cid=trackingcode&ecid=123
// Sets the campaign variable to "123"
// The plug-in replaces the URL's hash character with a question mark if a question mark doesn't exist.
s.campaign = getQueryParam('ecid');
// Given the URL https://example.com
// Does not set the campaign variable to a value.
s.pageURL = "https://example.com/?cid=trackingcode";
s.campaign = getQueryParam('cid');
// Given the URL https://example.com
// Sets the campaign variable to "trackingcode"
s.pageURL = "https://example.com/?cid=trackingcode";
s.campaign = getQueryParam('cid','',s.pageURL);
// Given the URL https://example.com
// Sets eVar2 to "123|trackingcode|true|300"
s.eVar1 = "https://example.com/?cid=trackingcode&ecid=123#location&pos=300";
s.eVar2 = getQueryParam('ecid,cid,location,pos','|',s.eVar1);
findParameterValue
和 getParameterValue
函数移到了 getQueryParam
函数findParameterValue
和 getParameterValue
。s.pt
和 AppMeasurement)。h
参数,允许代码查找在井号 (#
) 后找到的查询字符串参数