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 Adobe Account Team. They can arrange a meeting with a consultant for assistance.
The p_fo
plug-in is a utility that checks for the existence of a specific JavaScript object. If the object doesn’t exist, then the plug-in creates the object and returns true
. If the JavaScript object already exists on the page, then it returns false
. This plug-in is useful to run code exactly once on a page. Several other plug-ins rely on this code to work. This plug-in is unnecessary if you’re not worried about how many times code runs on a page, or if you don’t use any dependent plug-ins.
Adobe offers an extension that allows you to use most commonly-used plug-ins with the Web SDK.
p_fo
This plug-in is not yet supported for use within a manual implementation of the Web SDK.
Adobe offers an extension that allows you to use most commonly-used plug-ins with Adobe Analytics.
If you do not want to use the Common Analytics Plugins plug-in extension, you can use the custom code editor.
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: p_fo (pageFirstOnly) v3.0 (Requires AppMeasurement) */
function p_fo(c){if("-v"===c)return{plugin:"p_fo",version:"3.0"};a:{if("undefined"!==typeof window.s_c_il){var a=0;for(var b;a<window.s_c_il.length;a++)if(b=window.s_c_il[a],b._c&&"s_c"===b._c){a=b;break a}}a=void 0}"undefined"!==typeof a&&(a.contextData.p_fo="3.0");window.__fo||(window.__fo={});if(window.__fo[c])return!1;window.__fo[c]={};return!0};
/******************************************** END CODE TO DEPLOY ********************************************/
The p_fo
function uses the following arguments:
If the object doesn’t yet exist, this function returns true
and creates the object. If the object already exists, this function returns false
.
The following code will check for the existence of the “myobject” object within the page. If the “myobject” object doesn’t exist, then the code will create the “myobject” object and return the value of true. As a result, the code within the conditional statement (i.e. Console.log(‘hello’);) will run.
On the other hand, if the “myobject” object already exists when the p_fo call takes place, then the p_fo function will return the value of false and, thus, the conditional statement will be considered false. In this case, the code within the conditional statement will not run.
if(p_fo("myobject"))
{
console.log("hello");
}
NOTE: Every time a new page object/DOM loads (or the current page reloads), the object specified in the on argument will no longer exist and thus the p_fo plug-in will again return true the first time it runs after the page finishes loading.