Sent in private message.
Kindly check.
Alright so this is what you can see in your Adobe Launch logs:
🚀 [Custom Script] Failed to get previousPageName ReferenceError: getPreviousValue is not defined
at Object.source (launch-EN36e7398f32914ad28e21b622457f151b.min.js:2:1372)
at e.exports (launch-EN36e7398f32914ad28e21b622457f151b.min.js:2:3176)
at launch-EN36e7398f32914ad28e21b622457f151b.min.js:5:21796
at launch-EN36e7398f32914ad28e21b622457f151b.min.js:5:22513
at c (launch-EN36e7398f32914ad28e21b622457f151b.min.js:5:23887)
at i (launch-EN36e7398f32914ad28e21b622457f151b.min.js:5:23986)
at a (launch-EN36e7398f32914ad28e21b622457f151b.min.js:5:24281)
at r (launch-EN36e7398f32914ad28e21b622457f151b.min.js:5:24143)
at a (launch-EN36e7398f32914ad28e21b622457f151b.min.js:5:24341)
at o (launch-EN36e7398f32914ad28e21b622457f151b.min.js:5:24219)
console.<computed> @ VM392:85
M @ launch-EN36e7398f32914ad28e21b622457f151b.min.js:5
source @ launch-EN36e7398f32914ad28e21b622457f151b.min.js:2
e.exports @ launch-EN36e7398f32914ad28e21b622457f151b.min.js:2
(anonymous) @ launch-EN36e7398f32914ad28e21b622457f151b.min.js:5
(anonymous) @ launch-EN36e7398f32914ad28e21b622457f151b.min.js:5
c @ launch-EN36e7398f32914ad28e21b622457f151b.min.js:5
i @ launch-EN36e7398f32914ad28e21b622457f151b.min.js:5
a @ launch-EN36e7398f32914ad28e21b622457f151b.min.js:5
r @ launch-EN36e7398f32914ad28e21b622457f151b.min.js:5
a @ launch-EN36e7398f32914ad28e21b622457f151b.min.js:5
o @ launch-EN36e7398f32914ad28e21b622457f151b.min.js:5
a @ launch-EN36e7398f32914ad28e21b622457f151b.min.js:5
r @ launch-EN36e7398f32914ad28e21b622457f151b.min.js:5
a @ launch-EN36e7398f32914ad28e21b622457f151b.min.js:5
r @ launch-EN36e7398f32914ad28e21b622457f151b.min.js:5
a @ launch-EN36e7398f32914ad28e21b622457f151b.min.js:5
(anonymous) @ launch-EN36e7398f32914ad28e21b622457f151b.min.js:5
(anonymous) @ launch-EN36e7398f32914ad28e21b622457f151b.min.js:5
script @ launch-EN36e7398f32914ad28e21b622457f151b.min.js:3
ve @ launch-EN36e7398f32914ad28e21b622457f151b.min.js:5
i @ launch-EN36e7398f32914ad28e21b622457f151b.min.js:5
(anonymous) @ launch-EN36e7398f32914ad28e21b622457f151b.min.js:6
(anonymous) @ launch-EN36e7398f32914ad28e21b622457f151b.min.js:5
script @ launch-EN36e7398f32914ad28e21b622457f151b.min.js:3
ve @ launch-EN36e7398f32914ad28e21b622457f151b.min.js:5
i @ launch-EN36e7398f32914ad28e21b622457f151b.min.js:5
(anonymous) @ launch-EN36e7398f32914ad28e21b622457f151b.min.js:5
n @ launch-EN36e7398f32914ad28e21b622457f151b.min.js:5
ft @ launch-EN36e7398f32914ad28e21b622457f151b.min.js:6
(anonymous) @ launch-EN36e7398f32914ad28e21b622457f151b.min.js:6
(anonymous) @ launch-EN36e7398f32914ad28e21b622457f151b.min.js:6
Show 2 more frames
VM392:85 🚀 [Adobe Analytics] Loading script: https://assets.adobedtm.com/extensions/EP171e731c9ba34f1c950c36d26e3efd61/AppMeasurement.min.js
🚀 [Adobe Analytics] Loading script: https://assets.adobedtm.com/extensions/EP171e731c9ba34f1c950c36d26e3efd61/AppMeasurement_Module_ActivityMap.min.js
🚀 [Adobe Analytics] Creating AppMeasurement tracker with these report suites: "xgeo1xxpssin-ja-analyticstesting"
🚀 [Adobe Analytics] Setting the tracker as window.s
🚀 [Adobe Analytics] Setting version on tracker: "LCS4".
🚀 [Adobe Analytics] Calling custom script before settings.
🚀 [Adobe Analytics] Applying the following properties on tracker: "{"pageName":null,"currencyCode":"INR","trackInlineStats":true,"trackDownloadLinks":true,"trackExternalLinks":true,"linkDownloadFileTypes":"doc,docx,eps,jpg,png,svg,xls,ppt,pptx,pdf,xlsx,tab,csv,zip,txt,vsd,vxd,xml,js,css,rar,exe,wma,mov,avi,wmv,mp3,wav,m4v","linkTrackVars":"prop2"}".
🚀 [Adobe Analytics] Clear variables.
🚀 [Adobe Analytics] Set variables on the tracker.
🚀 [Adobe Analytics] Applying the following properties on tracker: "{"eVar1":null,"prop1":null,"events":"event1","linkTrackVars":"eVar1,prop1,events,prop2","linkTrackEvents":"event1,"}".
🚀 [Adobe Analytics] Firing page view beacon.
🚀 Rule "Page Load" fired.
🚀 Rule "Initialize Plug-ins | getPreviousValue" fired.
🚀 Rule "Initialize Plug-ins | getTimeParting" fired.
🚀 Condition "Value Comparison" for rule "Error Page - test" was not met.
🚀 Condition "Value Comparison" for rule "Home Page" was not met.
🚀 Rule "Online course demo" fired.
🚀 Rule "Set Zoom Level" fired.
🚀 Rule "Set Variable" fired.
I checked your library and you use both the Adobe Plugin extension and a custom code settings in the Adobe Analytics extension to deploy the getPreviousValue plugin.
1. I would avoid using Adobe Plugin extension. There is a current issue where even if you initialize one plugin it packages the sources code for all plugins provided by the extension which is a considerable amount code therefore making the adobe launch library pretty big for no reasons
2. You have deployed the plugin in Custom Code as requested and I followed same step and got same issue.
The reason behind it is that the documentation is incorrect in some ways. When you deploy the code in custom code it package it in a function and any code inside this function if not linked to any window object is not accessible outside the function scope:
"adobe-analytics": {
"displayName": "Adobe Analytics",
"hostedLibFilesBaseUrl": "https://assets.adobedtm.com/extensions/EP171e731c9ba34f1c950c36d26e3efd61/",
"settings": {
"orgId": "C50417FE52CB33480A490D4C@AdobeOrg",
"customSetup": {
"source": function(s) {
/* Adobe Consulting Plugin: getPreviousValue v3.0 */
function getPreviousValue(v,c){var k=v,d=c;if("-v"===k)return{plugin:"getPreviousValue",version:"3.0"};var a=function(){if("undefined"!==typeof window.s_c_il)for(var c=0,b;c<window.s_c_il.length;c++)if(b=window.s_c_il[c],b._c&&"s_c"===b._c)return b}();"undefined"!==typeof a&&(a.contextData.getPreviousValue="3.0");window.cookieWrite=window.cookieWrite||function(c,b,f){if("string"===typeof c){var h=window.location.hostname,a=window.location.hostname.split(".").length-1;if(h&&!/^[0-9.]+$/.test(h)){a=2<a?a:2;var e=h.lastIndexOf(".");if(0<=e){for(;0<=e&&1<a;)e=h.lastIndexOf(".",e-1),a--;e=0<e?h.substring(e):h}}g=e;b="undefined"!==typeof b?""+b:"";if(f||""===b)if(""===b&&(f=-60),"number"===typeof f){var d=new Date;d.setTime(d.getTime()+6E4*f)}else d=f;return c&&(document.cookie=encodeURIComponent(c)+"="+encodeURIComponent(b)+"; path=/;"+(f?" expires="+d.toUTCString()+";":"")+(g?" domain="+g+";":""),"undefined"!==typeof cookieRead)?cookieRead(c)===b:!1}};window.cookieRead=window.cookieRead||function(c){if("string"===typeof c)c=encodeURIComponent(c);else return"";var b=" "+document.cookie,a=b.indexOf(" "+c+"="),d=0>a?a:b.indexOf(";",a);return(c=0>a?"":decodeURIComponent(b.substring(a+2+c.length,0>d?b.length:d)))?c:""};var l;d=d||"s_gpv";a=new Date;a.setTime(a.getTime()+18E5);window.cookieRead(d)&&(l=window.cookieRead(d));k?window.cookieWrite(d,k,a):window.cookieWrite(d,l,a);return l};
/******************************************** END CODE TO DEPLOY ********************************************/ To palliate this issue you have 2 solutions: add the plugin to the analytics s object which is scoped globally in your implementation or scope it to window object.
Even doing this I found I was unable to make it work if I configured the previous value to be captured in an analytics variable when configure in the global section of Adobe Analytics extension. the reasons behind it is that the global variables seems to be initialized or the data element configured are being resolved before the custom code section is loaded as per logs above.
This is how you should do it:
1. Remove the configuration that you have in Global variable
2. In custom code section of adobe analytics extension we will place the plugin as is:
/* Adobe Consulting Plugin: getPreviousValue v3.0 */
function getPreviousValue(v,c){var k=v,d=c;if("-v"===k)return{plugin:"getPreviousValue",version:"3.0"};var a=function(){if("undefined"!==typeof window.s_c_il)for(var c=0,b;c<window.s_c_il.length;c++)if(b=window.s_c_il[c],b._c&&"s_c"===b._c)return b}();"undefined"!==typeof a&&(a.contextData.getPreviousValue="3.0");window.cookieWrite=window.cookieWrite||function(c,b,f){if("string"===typeof c){var h=window.location.hostname,a=window.location.hostname.split(".").length-1;if(h&&!/^[0-9.]+$/.test(h)){a=2<a?a:2;var e=h.lastIndexOf(".");if(0<=e){for(;0<=e&&1<a;)e=h.lastIndexOf(".",e-1),a--;e=0<e?h.substring(e):h}}g=e;b="undefined"!==typeof b?""+b:"";if(f||""===b)if(""===b&&(f=-60),"number"===typeof f){var d=new Date;d.setTime(d.getTime()+6E4*f)}else d=f;return c&&(document.cookie=encodeURIComponent(c)+"="+encodeURIComponent(b)+"; path=/;"+(f?" expires="+d.toUTCString()+";":"")+(g?" domain="+g+";":""),"undefined"!==typeof cookieRead)?cookieRead(c)===b:!1}};window.cookieRead=window.cookieRead||function(c){if("string"===typeof c)c=encodeURIComponent(c);else return"";var b=" "+document.cookie,a=b.indexOf(" "+c+"="),d=0>a?a:b.indexOf(";",a);return(c=0>a?"":decodeURIComponent(b.substring(a+2+c.length,0>d?b.length:d)))?c:""};var l;d=d||"s_gpv";a=new Date;a.setTime(a.getTime()+18E5);window.cookieRead(d)&&(l=window.cookieRead(d));k?window.cookieWrite(d,k,a):window.cookieWrite(d,l,a);return l};
/******************************************** END CODE TO DEPLOY ********************************************/Then we will use the doPlugins function to make sure our varaible is populate each time:
s.usePlugins = true;
s.doPlugins = function() {
s.prop2 = getPreviousValue(s.pageName,"gpv_Page");
}As everything is in the custom code section of adobe analytics evrything is accebile in the same scope no need to scope it to an object. You could achieve the same with a data element by putting the plugin code directly in your data element but it would mean that the plugin will only be available in this data element itself so if you need to use same plugin in another data element it won't work unless you scope it globally.
doPlugins will be executed each time a s.t and s.tl call is executed so you will be sure it always run, same logic as defining global section.