Adobe plug-in: getPageName


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 getPageName plug-in creates an easy to read, friendly formatted version of the current URL. Adobe recommends using this plug-in if you want a pageName value that is easy to set and understand in reporting. This plug-in is unnecessary if you already have a naming structure for the pageName variable, such as through a data layer. It is best used when you don’t have another solution to set the pageName variable.

Install the plug-in using 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 Adobe Experience Platform Data Collection 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: getPageName v4.2 */
var getPageName=function(si,qv,hv,de){var a=si,b=qv,f=hv,e=de;if("-v"===a)return{plugin:"getPageName",version:"4.2"};a:{if("undefined"!==typeof window.s_c_il){var d=0;for(var g;d<window.s_c_il.length;d++)if(g=window.s_c_il[d],g._c&&"s_c"===g._c){d=g;break a}}d=void 0}"undefined"!==typeof d&&(d.contextData.getPageName="4.2");var c=location.hostname,h=location.pathname.substring(1).split("/"),l=h.length,"&"),m=k.length;d=location.hash.substring(1).split("&");g=d.length;e=e?e:"|";a=a?a:c;b=b?b:"";f=f?f:"";if(1===l&&""===h[0])a=a+e+"home";else for(c=0;c<l;c++)a=a+e+decodeURIComponent(h[c]);if(b&&(1!==m||""!==k[0]))for(h=b.split(","),l=h.length,c=0;c<l;c++)for(b=0;b<m;b++)if(h[c]===k[b].split("=")[0]){a=a+e+decodeURIComponent(k[b]);break}if(f&&(1!==g||""!==d[0]))for(f=f.split(","),k=f.length,c=0;c<k;c++)for(b=0;b<g;b++)if(f[c]===d[b].split("=")[0]){a=a+e+decodeURIComponent(d[b]);break}return a.substring(a.length-e.length)===e?a.substring(0,a.length-e.length):a};
/******************************************** END CODE TO DEPLOY ********************************************/

Use the plug-in

The getPageName function uses the following arguments:

  • si (optional, string): An ID inserted into the beginning of the string representing the ID of the site. This value can either be a numeric ID or a friendly name. When not set, it defaults to the current domain.
  • qv (optional, string): A comma-delimited list of query string parameters that, if found in the URL, are added to the string
  • hv (optional, string): A comma-delimited list of parameters found in the URL hash that, if found in the URL, are added to the string
  • de (optional, string): The delimiter to split up individual parts of the string. Defaults to a pipe (|).

The function returns a string containing a friendly-formatted version of the URL. This string is typically assigned to the pageName variable, but can be used in other variables as well.


// Given the URL, sets the page variable to "|mail|u|0".
s.pageName = getPageName();

// Given the URL, sets the page variable to "example|mail|u|0".
s.pageName = getPageName("example");

// Given the URL, sets the page variable to "|home".
// When the code runs on a URL that does not contain a path, it always adds the value of "home" to the end of the return value.
s.pageName = getPageName();

// Given the URL, sets the page variable to "example|home".
s.pageName = getPageName("example","","","|");

// Given the URL
// Sets the page variable to "|en|booking|room-booking.html".
s.pageName = getPageName();

// Given the URL
// Sets the page variable to "example: en: booking: room-booking.html: cid=1235: arrive=05-26: numGuests=2"
s.pageName = getPageName("example","cid","arrive,numGuests",": ");

Upgrading from Previous Versions

Version 4.0+ of the getPageName plug-in is not dependent on the existence of the Adobe Analytics’ AppMeasurement object (i.e. the s object). If you upgrade to this version, change the code that calls the plug-in by removing any instances of the s object from the call. For example, change s.getPageName(); to getPageName();.

Version History

4.2 (March 19, 2021)

  • Added version number as context data.

4.1 (September 17, 2019)

  • Changed default delimiter value to a pipe character (from a colon + space).

4.0 (May 22, 2018)

  • Complete reanalysis/rewrite of plug-in

On this page