Expand my Community achievements bar.

s.events is giving undefined

Avatar

Level 3

s.events  value is giving undefined when I declare like this below 

Here is the code follows:

 

s.linkTrackVars = "events";
s.linkTrackEvents = "event140" ;

s.usePlugins=true;

s.doPlugins = function() {

s.events = s.events + ",event140= xyz";

}

Here , in output I am getting in the calls is 

event = undefined ,,event140= xyz

But then when , I have other rules having event firing , I am getting 

event = event50 ,event140= xyz

 

Can anyone tell me , do I need to remove the s.events in --s.events = s.events + ",event140= xyz" but then , how will my other rules events will reflect?

Thanks!

 

2 Replies

Avatar

Community Advisor and Adobe Champion

Or you can check if there is any value in s.events like so:

 

s.events = s.events ? s.events + ",event140=xyz" : "event140=xyz";

 

Basically this is a shorthand if statement:

 

If s.events has a value

THEN

use s.events + ",event140=xyz" (notice the comma)

ELSE
use "event140=xyz" (no comma)

 

 

If there is no s.events then you should just get: "event140=xyz" 

If s.events is say "event12", then you should get "event12,event140=xyz"

If s.events is "event13,", then you should get "event13,,event140=xyz"

 

 

Not sure how worried you are about having 2 commas (that would drive me crazy, lol).. but you could fix that by replacing ",," with "," if it bothers you.

Avatar

Community Advisor

Hey @SA30 

 

There is a common analytics plugin available for this which is appendToList. It is used to append a value to existing set of values as the name suggests.

 

I have put a few examples from the official documentation link (https://experienceleague.adobe.com/docs/analytics/implementation/vars/plugins/apl.html?lang=en) below and highlighted your use case.

 

// Set the events variable to "event22,event24,event23".


s.events = "event22,event24";
s.events = apl(s.events,"event23");

 

// The events variable remains unchanged because the apl function does not add duplicate values


s.events = "event22,event23";
s.events = apl(s.events,"event23");

 

// Set the events variable to "event23" if the events variable is blank


s.events = "";
s.events = apl(s.events,"event23");

 

// Append a value to eVar5. The value of prop4 remains unchanged.
// The value of eVar5 is "hello|people|today".


s.prop4 = "hello|people";
s.eVar5 = apl(s.prop4, "today", "|");

 

// Sets prop4 to "hello|people,today". Be mindful of correct delimiters!


s.prop4 = "hello|people";
s.prop4 = apl(s.prop4, "today");

 

// Sets the events variable to "event22,event23,EVentT23". Be mindful of capitalization when using the cc argument!


s.events = "event22,event23";
s.events = apl(s.events,"EVenT23", ",", ",", true);

 

// Sets the events variable to "event22,event23,event24,event25".


s.events = "event22,event23";
s.events = apl(s.events, "event23,event24,event25");

 

// Sets linkTrackVars to "events,eVar1,campaign".
// The last three arguments at the end of this apl call are not necessary because they match the default argument values.


s.linkTrackVars = "events,eVar1";
s.linkTrackVars = apl(s.linkTrackVars, "campaign", ",", ",", false);

 

// This apl call does not do anything because the code does not assign the returned value to a variable.


s.events = "event22,event24";
apl(s.events, "event23");

 

// Sets the list2 variable to "apple-APPLE-Apple".
// Since the two delimiter arguments are different, the value passed in is delimited by "|", then joined together by "-".


s.list2 = "apple|APPLE";
s.list2 = apl(s.list2, "Apple", "|", "-", true);

 

// Sets the list3 variable to "value1,value1,value1" (unchanged).
// Only new values are deduplicated. Existing duplicate values remain.


s.list3 = "value1,value1,value1";
s.list3 = apl(s.list3,"value1");

 

 

Hope the above helps. This plugin is used quite extensively.

 

Regards,

Abhinav