Expand my Community achievements bar.

SOLVED

Capture previous page name

Avatar

Level 3

How to capture previous page name value in prop using adobe dtm?

1 Accepted Solution

Avatar

Correct answer by
Level 3

Here is what I did, and hopefully it will work for you.  I created a new data element and set the type to custom script.  In the editor I added the getPreviousValue() and split() plugin code and then called getPreviousValue() with the current page name, returning the return value.  I use this data element on all page views to fill in a prop and an eVar with the previous page name.

View solution in original post

6 Replies

Avatar

Level 10

Within Analytics, you could look into the pathing or previous page report.

Pathing

Previous Page

As for DTM, you could do this a number of ways, I'll list a few below:

1) Store the Page Name in a cookie or data element and retrieve and set to a prop when needed

2) Set the previous page name in a query string (site.com/page2?ppn=page1) and retrieve it when needed

3) If you are just looking for the referring domain (IE if someone found your site via another domain or search engine) you could tap into document.referrer for the referring URL.

Thanks,
Jantzen

Avatar

Level 3

Hi Jantzen Belliston,

Thanks for helping me. Right now my next page flow reports have data in it. I would like to have a prop to capture them so that i can use it in my analysis workspace. But can you explain more about how to setup previous page report into a prop using cookie or data element?

Avatar

Employee

Hi,

You can use the 'getpreviousvalue' plug-in to achieve this.

Using this plug-in, you can capture the value of an Analytics variable on the next page view. For an example, capturing the s.pageName value from the previous page view into a Custom Traffic variable i.e. previous page value in a variable of your choice.

Avatar

Level 3

Hi Abhijeet,

Thanks for your Idea. But I use DTM to manage my s_code file. So how do you suggest me to include the code given on getPreviousValue this page?

Avatar

Correct answer by
Level 3

Here is what I did, and hopefully it will work for you.  I created a new data element and set the type to custom script.  In the editor I added the getPreviousValue() and split() plugin code and then called getPreviousValue() with the current page name, returning the return value.  I use this data element on all page views to fill in a prop and an eVar with the previous page name.

Avatar

Level 2

Hello Christy, I like your approach because I'm not comfortable with putting it in Library Management so that I can keep my code most recent version. I'm working with a Single Page App, so i'm not sure if this will work. Something's not working correctly because I'm not seeing anything returned.

Here's my data element custom code:

    /*

    * Plugin: getPreviousValue_v1.0 - return previous value of designated

    *  variable (requires split utility)

    */

    var s = _satellite.getToolsByType('sc')[0].getS();

    s.getPreviousValue=new Function("v","c","el",""

    +"var s=this,t=new Date,i,j,r='';t.setTime(t.getTime()+1800000);if(el"

    +"){if(s.events){i=s.split(el,',');j=s.split(s.events,',');for(x in i"

    +"){for(y in j){if(i[x]==j[y]){if(s.c_r(c)) r=s.c_r(c);v?s.c_w(c,v,t)"

    +":s.c_w(c,'no value',t);return r}}}}}else{if(s.c_r(c)) r=s.c_r(c);v?"

    +"s.c_w(c,v,t):s.c_w(c,'no value',t);return r}");

    /*

    * Utility Function: split v1.5 - split a string (JS 1.0 compatible)

    */

    s.split=new Function("l","d",""

    +"var i,x=0,a=new Array;while(l){i=l.indexOf(d);i=i>-1?i:l.length;a[x"

    +"++]=l.substring(0,i);l=l.substring(i+d.length);}return a");

    return(s.getPreviousValue(s.pageName,'gpv_pn', 'event1'));

Does this look like your implementation?

Thanks!