Custom code variables is not triggerring along with pagetag rule. | Community
Skip to main content
October 17, 2024
Solved

Custom code variables is not triggerring along with pagetag rule.

  • October 17, 2024
  • 2 replies
  • 2317 views

i could not see my custom code not triggerring used along with pagetag variables set in template.

s.usePlugins = true;

s.doPlugins = function(s)
{
/* Desired code */
s.eVar2 = getPreviousValue(s.pageName,"gpv_Page");
s.campaign = getQueryParam('cid');
s.prop2= "fired";
}
//doplugins()
/* Plugin Section - Add plugin code here*/
/* 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: getQueryParam v4.0.1 */
function getQueryParam(a,d,f){function n(g,c){c=c.split("?").join("&");c=c.split("#").join("&");var e=c.indexOf("&");if(g&&(-1<e||c.indexOf("=")>e)){e=c.substring(e+1);e=e.split("&");for(var h=0,p=e.length;h<p;h++){var l=e[h].split("="),q=l[1];if(l[0].toLowerCase()===g.toLowerCase())return decodeURIComponent(q||!0)}}return""}if("-v"===a)return{plugin:"getQueryParam",version:"4.0.1"};var b=function(){if("undefined"!==typeof window.s_c_il)for(var g=0,c;g<window.s_c_il.length;g++)if(c=window.s_c_il[g],c._c&&"s_c"===c._c)return c}();"undefined"!==typeof b&&(b.contextData.getQueryParam="4.0");if(a){d=d||"";f=(f||"undefined"!==typeof b&&b.pageURL||location.href)+"";(4<d.length||-1<d.indexOf("="))&&f&&4>f.length&&(b=d,d=f,f=b);b="";for(var m=a.split(","),r=m.length,k=0;k<r;k++)a=n(m[k],f),"string"===typeof a?(a=-1<a.indexOf("#")?a.substring(0,a.indexOf("#")):a,b+=b?d+a:a):b=""===b?a:b+(d+a);return b}};
/******************************************** END CODE TO DEPLOY ********************************************/

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by Jennifer_Kunz

You definitely should not need a CNAME set up for the plugins (or really for any part of your implementation). The getPreviousValue plugin uses Javascript to write a first-party cookie- nothing to do with CNAMEs. And your prop2 has nothing to do with cookies at all. So I'm guessing your problem was more that your overall beacon wasn't firing, rather than something about your plugins here?
In which case: overall, by default, Adobe will set first party cookies using Javascript. If you have a CNAME, the visitor ID/MCID cookie can be set as a more secure HTTP cookie, which for a while got around some limitations in Apple but no longer. These days, a CNAME might help you get around some ad blockers, but even that is less and less likely. 

I can copy and paste your code into the dev console of my random little test website (https://www.digitaldatatactics.com/learningSite/), fire a beacon with an s.t() function, and see each of those variables being set. If you're still not seeing beacons, then there is a problem somewhere else in your implementation... but you should already have all you need to get this working (no CNAME required).

2 replies

kautuk_sahni
Community Manager
Community Manager
October 18, 2024

@Tof_Jossic @yuhuisg @nnakirikanti @Anuhya-Y @SatheeskannaK @brekrut Curious to hear SMEs perspectives on this question. Do you all mind sharing your thoughts?

Kautuk Sahni
Jennifer_Kunz
Adobe Champion
Adobe Champion
October 22, 2024

Everything in there seems to be set up fine, so we might need more details. Is this code you've set up in your Analytics extension, or in a rule? Are you seeing your variables fire in some situations but not others? LinkTrackVars can be tricky like that, where on custom link (s.tl) beacons it won't pick up variables unless they were specific in linkTrackVars. 

October 23, 2024

thanks for the reply, custom codes are working it looks like there was some cache issue. plugin custom codes were not returning value were not working as cookies are not setup from plugin as we dont have cname setup which is required i guess.

October 25, 2024

Ah, yeah, I can imagine the plugin cookies struggle with that kind of domain. It looks like in the getPreviousValue plugin they expect the URL to be a certain way- it's going off the hostname, which for that URL would be "publish-e-254678", and it doesn't know how to handle a hostname with no dots. 
It wouldn't be too hard to tweak the plugin code (or just rewrite it) to give you more control over the domain. Is https://publish-e-254678/adobeaemcloud.com going to be your permanent domain? Are you using other Adobe plugins that rely on cookies?


Thanks Jennifer, the above domain is not our live url we get live url like www.lt*******.com.

And I am using getvalonce, previous value, new/repeat plugins