Expand my Community achievements bar.

SOLVED

No Analytics Call Generated after adding Custom Code to Analytics Extension

Avatar

Level 1

Hi,

I have a dev site set up on adobeaemcloud.com where I am tracking page load & button click rules. We have ACDL implemented here so cmp:show & cmp:click events are triggered on page load & button click respectively.

Initially, the plugin code for getPreviousValue & others was blocking the server calls, so I added the Common Analytics extension plugin.

My Page Load  Rule - Initialising the plugins that I need, set variables & send beacon

hashaikh1198_0-1662685713992.png

Custom Code config in Adobe Analytics Extension

hashaikh1198_1-1662685786442.png

As soon as I add the code in comments (custom code config) into the function, the analytics server calls get blocked. 

hashaikh1198_2-1662685996172.png

 

However, even though I have generic plugin code as shown in the above screenshot (which was working earlier), its still blocking the server calls.

Would really appreciate any suggestions. 

 

1 Accepted Solution

Avatar

Correct answer by
Level 1

Thanks. To clarify, I had to create a data element for getPageName() as without the data element the below code didn't work. I was not getting Page Name at all w/o the DE.

 

s.pageName = getPageName();

s.eVar4 =  getPageName();

 

I have now updated custom code to 

/* Plugin Config */
s.usePlugins=true;
s.doPlugins = s_doPlugins

function s_doPlugins(s)
{
s.eVar17 = s.getNewRepeat();
s.eVar19 = s.getTimeSinceLastVisit();
s.eVar20 = s.getVisitNum();
s.campaign = s.getQueryParam('fbclid,q');
s.eVar21 = s.getQueryParam('fbclid,q');

s.pageName = _satellite.getVar('getPageName');
s.eVar7 = s.getPreviousValue(s.pageName,'gpv_Page');
}

 

Rules:

1. Rule 1: Initialises all plugins needed on Library Loaded - Page top

2. Rule 2: Fires on an event and sets variables, no custom code added to the rule

3. Rule 3: For Scroll Depth Tracking

 

Data element:

1. getPageName 

hashaikh1198_0-1662709567936.png

 

2. Other common analytics plugin related DE

 

Still unable to get Previous page name. See function in console below

hashaikh1198_1-1662709641069.png

 

I read this thread where the issue was due to the domain & was resolved after publishing to production. As my domain for my dev environment is adobeaemcloud.com, is it possible that would be causing the issue?

 

 

View solution in original post

11 Replies

Avatar

Community Advisor

1. If you're letting Launch manage the Analytics library for you, ensure that you have made the tracker globally accessible. This checkbox setting is available in the Adobe Analytics extension > Library Management > Manage the library for me > Make tracker globally accessible.

2. In Common Analytics Plugins, verify that you've enabled your 3 plugins (found in your commented code): getPercentPageViewed, getPageName, getPreviousValue.

 

If you still get the same result after performing the above 2 steps, then comment your code block by block (or line by line) till you're able to isolate the problem.

Avatar

Level 1

Hi @yuhuisg 

Please see below response.

 

1. Tracker has been made globally accessible as per your comment.

hashaikh1198_0-1662693658505.png

 

2. The plugins needed have been enabled in the Common Analytics Plugin

 

3. Pretty sure the code highlighted below is blocking the server calls. I had added that code to track previous page name.

Would you know why that blocks the server calls & if there's an alternate method to track previous page without the plugin.

PS: Cannot add Previous page name to the Datalayer

hashaikh1198_1-1662693724099.png

 

Avatar

Community Advisor

Does s.getPageName() work by itself?

In your browser console, do you see any errors when loading your page, in particular, errors that might be related to this custom code? If so, please share a screenshot of those errors.

Avatar

Level 1

Not really. I've just sent you screenshots of the errors. 

I see this error in relation to getPageName() for the Page Scroll Rule in Launch..

Failed to execute "Send Beacon" for "Page Scroll 25%" rule. e.getPageName is not a function
TypeError: e.getPageName is not a function

Custom code shown below

hashaikh1198_0-1662698011930.png

 

Avatar

Community Advisor

Thanks for the screenshots.

The error is stated right there: "e.getPageName is not a function"

So that means, for some reason, the getPageName() plugin is not available when your scroll rule fires. To see if that plugin is really absent, in your browser console, run "s.getPageName()" and see if it returns a valid result or an error. If it returns an error, then you need to enable this plugin.

Avatar

Level 1

Thanks. It does give the same error in console on executing "s.getPageName()

I've created a rule to fire on Page top & action = Initialise plugins. See below. 

You can see getPageName is ticked here. However, there are still no server calls for any Launch rules.

hashaikh1198_0-1662699036416.png

I even tried to set an action within the Page Load & Page scroll rule to initialising the plugin within the rule & it still gives the same error.

Avatar

Community Advisor

Oh! getPageName is initialised as a global function within "window", not "s". Notice the "window" in the 4th column of the Initialize action.

Try changing your code from "s.getPageName()" to just "getPageName()" or "window.getPageName()".

Avatar

Level 1

Thanks. Using just "getPageName()" worked but I also had to create a data element for the plugin as shown below & assign it to an eVar in the page load rule. 

hashaikh1198_0-1662705085178.png

 

However, when I add any of the below options (within the custom code) to get the Previous page name, I am not able to get eVar7 = Previous page name in server calls. I am testing links that open in a new tab. Assuming it should still give the previous page names for these ones.

Note: getPreviousValue() has been enabled within the plugin & we cannot create a data element for getPreviousValue(). I've also enabled p_fo which is needed for getPreviousValue()

 

Option 1:

s.pageName = getPageName();
s.eVar7 = s.getPreviousValue(s.pageName, "gpv_Page")

 

Option 2:

s.pageName = getPageName();

s.eVar4 =  getPageName();
s.eVar7 = s.getPreviousValue(s.eVar4); 

 

Option 3:

s.pageName = getPageName();

if(s.pageName){
s.eVar7 = s.getPreviousValue(s.pageName,'gpv_Page');
}  

 

Option 4:

s.pageName = getPageName();

s.eVar4 =  getPageName();

 

if(s.pageName){
s.eVar7 = s.getPreviousValue(s.eVar4);

}

hashaikh1198_4-1662705503442.png

 

 

Avatar

Community Advisor

Firstly, since you had created a data element for getPageName(), then you should use that data element instead to set your s.pageName. I.e.

s.pageName = _satellite.getVar('getPageName data element');

Anyway, I would expect that any of your 4 options would work. I wonder, if you use the above _satellite.getVar() method, will you be able to set eVar7 properly? E.g. from option 1

s.pageName =  _satellite.getVar('getPageName data element');

s.eVar7 = s.getPreviousValue(s.pageName, "gpv_Page")

Avatar

Correct answer by
Level 1

Thanks. To clarify, I had to create a data element for getPageName() as without the data element the below code didn't work. I was not getting Page Name at all w/o the DE.

 

s.pageName = getPageName();

s.eVar4 =  getPageName();

 

I have now updated custom code to 

/* Plugin Config */
s.usePlugins=true;
s.doPlugins = s_doPlugins

function s_doPlugins(s)
{
s.eVar17 = s.getNewRepeat();
s.eVar19 = s.getTimeSinceLastVisit();
s.eVar20 = s.getVisitNum();
s.campaign = s.getQueryParam('fbclid,q');
s.eVar21 = s.getQueryParam('fbclid,q');

s.pageName = _satellite.getVar('getPageName');
s.eVar7 = s.getPreviousValue(s.pageName,'gpv_Page');
}

 

Rules:

1. Rule 1: Initialises all plugins needed on Library Loaded - Page top

2. Rule 2: Fires on an event and sets variables, no custom code added to the rule

3. Rule 3: For Scroll Depth Tracking

 

Data element:

1. getPageName 

hashaikh1198_0-1662709567936.png

 

2. Other common analytics plugin related DE

 

Still unable to get Previous page name. See function in console below

hashaikh1198_1-1662709641069.png

 

I read this thread where the issue was due to the domain & was resolved after publishing to production. As my domain for my dev environment is adobeaemcloud.com, is it possible that would be causing the issue?

 

 

Avatar

Level 3

Hi,

 

I am still unable to resolve this issue. As mentioned in the previous comment - 

Still unable to get Previous page name even after tryingbelow options:

 

Option 1 - I have tried creating a data element for "Get Previous Page" using below code & assigning it to "Page Loaded" Rule

 

 

/* 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 ********************************************/

/******************************************* BEGIN CODE TO DEPLOY *******************************************/
/* Adobe Consulting Plugin: getPageName v4.2 */
var getPageName=function(si,qv,hv,de){var a=si,b=qv,f=hv,e=de;if("-v"===a)return{plugin:"getPageName",version:"4.2"};a:{if("undefined"!==typeof window.s_c_il){var d=0;for(var g;d<window.s_c_il.length;d++)if(g=window.s_c_il[d],g._c&&"s_c"===g._c){d=g;break a}}d=void 0}"undefined"!==typeof d&&(d.contextData.getPageName="4.2");var c=location.hostname,h=location.pathname.substring(1).split("/"),l=h.length,k=location.search.substring(1).split("&"),m=k.length;d=location.hash.substring(1).split("&");g=d.length;e=e?e:"|";a=a?a:c;b=b?b:"";f=f?f:"";if(1===l&&""===h[0])a=a+e+"home";else for(c=0;c<l;c++)a=a+e+decodeURIComponent(h[c]);if(b&&(1!==m||""!==k[0]))for(h=b.split(","),l=h.length,c=0;c<l;c++)for(b=0;b<m;b++)if(h[c]===k[b].split("=")[0]){a=a+e+decodeURIComponent(k[b]);break}if(f&&(1!==g||""!==d[0]))for(f=f.split(","),k=f.length,c=0;c<k;c++)for(b=0;b<g;b++)if(f[c]===d[b].split("=")[0]){a=a+e+decodeURIComponent(d[b]);break}return a.substring(a.length-e.length)===e?a.substring(0,a.length-e.length):a};
/******************************************** END CODE TO DEPLOY ********************************************/

var a = s.getPageName();

return(s.getPreviousValue(a));

 

Option 2 - Added below code to the custom code section of Page loaded rule - 

 

window.s.linkTrackVars = "eVar1,eVar2,eVar3,eVar4,eVar5,eVar6,eVar7,eVar8,eVar9,eVar10,eVar11,eVar12,eVar13,eVar14,eVar15,eVar16,eVar17,eVar19,eVar20,prop7";
window.s.linkTrackEvents = "event1";

s.pageName = s.getPageName();

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

 

Option 3 - Added below code to the custom code section of Adobe Analytics extension

/* Plugin Config */
s.usePlugins=true;
s.doPlugins = s_doPlugins

function s_doPlugins(s)
{
s.eVar17 = s.getNewRepeat();
s.eVar19 = s.getTimeSinceLastVisit();
s.eVar20 = s.getVisitNum();
s.campaign = s.getQueryParam('fbclid,q');
s.eVar21 = s.getQueryParam('fbclid,q');

s.pageName = _satellite.getVar('getPageName');
s.eVar7 = s.getPreviousValue(s.pageName,'gpv_Page');
}

 

These options either interrupt the server call or don't capture the value of eVar7 or prop7 as the previous page name.