Expand my Community achievements bar.

SOLVED

getPreviousValue Plugin

Avatar

Level 3

Hi,

 I want to capture getPreviousValue in prop.

 

I have exactly followed the Install the plug-in using tags in Adobe Experience Platform steps as mentioned in this given link ( https://experienceleague.adobe.com/docs/analytics/implementation/vars/plugins/getpreviousvalue.html?... ).

 

But I see the value in the debugger as c.getPreviousValue.

 

How to capture it in a prop?

 

Thank you.

 

 

1 Accepted Solution

Avatar

Correct answer by
Community Advisor

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_Acti...
[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. 

 

 

View solution in original post

13 Replies

Avatar

Community Advisor

You also need to add custom code to use the plugin to allocate the value you need to an evar as follow:

// 1. Sets prop7 to the cookie value contained in gpv_Page
// 2. Resets the gpv_Page cookie value to the page variable
// 3. If the page variable is not set, reset the gpv_Page cookie expiration
s.prop7 = getPreviousValue(s.pageName,"gpv_Page");

Avatar

Level 3

Hi,

 

I have set prop3 in report suite as Previous Page Value.

 

Can you share the code snippet or link to be added? Also where should the code be added in the analytics extension or the rule created for the plugin?

 

Can you please elaborate the above steps?

 

 

Avatar

Community Advisor

There are 2 options:

1. Create a data element which will get the previous value and use it Adobe Analytics action or extension configuration view by mapping prop3 to your data element name

 

2. Use custom code in the adobe analytics action or adobe analytics extension view under custom code section to map 

s.prop3 = getPreviousValue(s.pageName,"gpv_Page");

 

Solution 1 (Best option):

1. Navigate to Data Elements

2. Create New Data Element

3. Configure new data element as follow:

Name: previousPageName

Extension: Core

Data Element Type: Custom Code

4. Click on Open editor and paste this code:

try {
  return getPreviousValue(s.pageName,"gpv_Page");
} catch (e) {
  _satellite.logger.error('Failed to get previousPageName', e);
}

5. Now we need to update Adobe Analytics call, you have two options either to do it in the set variable action or in the Analytics extension itself

  a. For the analytics extension itself you will need to use Global Variables section, select your prop3 set as and click on the little icon and select your data element name

  b. for the Set variable action select the prop3 set as and click on the little icon and select your data element name

In both cases once data element selected you should see in field %previousPageName%

That should be you done.

 

Solution 2:

1.Directly in the adobe analytics extension configuration view scroll to Configure tracker using custom code, then open editor.

OR

In the Set variables action scroll down to Custom Code and click on Open editor

2. Paste this code

 

try {
  s.prop3 = getPreviousValue(s.pageName,"gpv_Page");
} catch (e) {
  _satellite.logger.error('Failed to get previousPageName', e);
}

Hope this helps

Avatar

Level 3

Thank you for your detailed response, it is very helpful!

Avatar

Level 3

I cannot see anything in the adobe debugger.

 

Added 

try {
s.prop3 = getPreviousValue(s.pageName,"gpv_Page");
} catch (e) {
_satellite.logger.error('Failed to get previousPageName', e);
}

in the custom code of page load rule.

 

The logs shows this Error: [Custom Script] Failed to get previousPageName ReferenceError: getPreviousValue is not defined 

 

 

Avatar

Level 3

Hi,

 

I retried Solution 2 .1 

my prop value shows as %previousPageName%

and in the console Error shows as below:

[Custom Script] Failed to get previousPageName ReferenceError: getPreviousValue is not defined

 

Avatar

Employee Advisor

With the new plugin, the data is also set in context variables (c.getPreviousValue). Another quick solution would be to add a processing rule to read this value and set in the desired prop. 

If you need more info about processing rules, you can read here: Create processing rules

Avatar

Community Advisor

Could you provide the URL to your dev build from Adobe Launch. Will look at source code and see how you deployed the plugin. So basically if you go to your environments and copy paste the URL library that would be enough for me to have a look at.

Avatar

Correct answer by
Community Advisor

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_Acti...
[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. 

 

 

Avatar

Level 3

Thanks a lot for the brief explanation, it's now working.

But I can see the values in the Adobe Debugger, not on the console.

 

Also is the approach for the SPA page different, because for SPA the previous page value shows undefined?

 

 

Avatar

Community Advisor

For the logs with a , these are the one from the Adobe Launch library and they are enabled by setting the flag _satellite.setDebug('true'). They should be outputted in the developer console once enabled. I usually use the Launch command extension to enable debug mode: https://chrome.google.com/webstore/detail/launch-command/nkjhamgjeocefocmpbcjfmohkjgildki

 

If you want to see analytics call in the developer console you can do it as well by using  s.debugTracking = true

 

I usually paste it in the custom code section of Adobe Analytics extension and wrap it in this condition so it is only displayed when adobe launch debug mode is on:

if(localStorage.getItem('com.adobe.reactor.debug') == 'true') {
  s.debugTracking = true;
}

For SPA it should be same approach, however you would need to make sure pageName is updated on "page content" change. It could be route change or any other ways you and your company implemented it.

If it is undefined it could either be s.pageName is not populated or it is populated but not updated when route change.

 

Also same implementation method is true for all Adobe Plugins. If they are not  part of the s (anaytics) object, you need to make sure that all code using the plugin are placed in same custom code section. One solution is to scope the plugin to s object by using s.getPreviousValue