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 getValOnce
plug-in prevents a variable from being set equal to the same value more than once. Adobe recommends using this plug-in when you would like to deduplicate occurrences where a visitor refreshes a page or otherwise visit a given page multiple times. This plug-in is unnecessary if you are not worried about the ‘Occurrences’ metric in Analysis Workspace.
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.
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: getValOnce v3.0 (Requires AppMeasurement) */
function getValOnce(vtc,cn,et,ep){var e=vtc,k=cn,l=et,m=ep;if(arguments&&"-v"===arguments[0])return{plugin:"getValOnce",version:"3.0"};var c=function(){if("undefined"!==typeof window.s_c_il)for(var b=0,a;b<window.s_c_il.length;b++)if(a=window.s_c_il[b],a._c&&"s_c"===a._c)return a}();"undefined"!==typeof c&&(c.contextData.getValOnce="3.0");window.cookieWrite=window.cookieWrite||function(b,a,d){if("string"===typeof b){var h=window.location.hostname,c=window.location.hostname.split(".").length-1;if(h&&!/^[0-9.]+$/.test(h)){c=2<c?
c:2;var f=h.lastIndexOf(".");if(0<=f){for(;0<=f&&1<c;)f=h.lastIndexOf(".",f-1),c--;f=0<f?h.substring(f):h}}g=f;a="undefined"!==typeof a?""+a:"";if(d||""===a)if(""===a&&(d=-60),"number"===typeof d){var e=new Date;e.setTime(e.getTime()+6E4*d)}else e=d;return b&&(document.cookie=encodeURIComponent(b)+"="+encodeURIComponent(a)+"; path=/;"+(d?" expires="+e.toUTCString()+";":"")+(g?" domain="+g+";":""),"undefined"!==typeof cookieRead)?cookieRead(b)===a:!1}};window.cookieRead=window.cookieRead||function(b){if("string"===
typeof b)b=encodeURIComponent(b);else return"";var a=" "+document.cookie,d=a.indexOf(" "+b+"="),c=0>d?d:a.indexOf(";",d);return(b=0>d?"":decodeURIComponent(a.substring(d+2+b.length,0>c?a.length:c)))?b:""};return e&&(k=k||"s_gvo",l=l||0,m="m"===m?6E4:864E5,e!==this.c_r(k))?(c=new Date,c.setTime(c.getTime()+l*m),cookieWrite(k,e,0===l?0:m),e):""};
/******************************************** END CODE TO DEPLOY ********************************************/
The getValOnce
method uses the following arguments:
vtc
(required, string): The variable to check and see if it was just previously set to an identical valuecn
(optional, string): The name of the cookie that holds the value to check. Defaults to "s_gvo"
et
(optional, integer): The expiration of the cookie in days (or minutes, depending on the ep
argument). Defaults to 0
, which expires at the end of the browser sessionep
(optional, string): Only set this argument if the et
argument is also set. Set this argument to "m"
if you want the et
argument to expire in minutes instead of days. Defaults to "d"
, which sets the et
argument in days.If the vtc
argument and cookie value match, this method returns an empty string. If the vtc
argument and cookie value do not match, the method returns the vtc
argument as a string.
Use this call to prevent the same value being passed in to s.campaign more than once in a row for next 30 days:
s.campaign=s.getValOnce(s.campaign,"s_campaign",30);
In the above call, the plug-in will first compare the value already contained in the s_campaign cookie with the value coming from the current s.campaign variable. If a match is not made, the plug-in will set the s_campaign cookie equal to the new value coming from s.campaign and then return the new value. This comparison will happen for the next thirty days
Use this call to prevent the same value being set throughout the session:
s.eVar2=s.getValOnce(s.eVar2,"s_ev2",0,"m");
This code prevents the same value from being passed into s.eVar2 more than once in a row throughout a user’s session. It also ignores the “m” value in the epargument (at the end of the call) since the expiration time is set equal to 0. The code also stores the comparison value in the s_ev2 cookie.
t
parameter.k
variable used to restrict it to the plug-in only. This change prevents possible interference with other code on the page.