Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
BedrockMission!

Learn More

View all

Sign in to view all badges

javascript conditions in DTM custom code

Avatar

Avatar
Boost 1
Level 2
kunjalk3064084
Level 2

Like

1 like

Total Posts

8 posts

Correct Reply

0 solutions
Top badges earned
Boost 1
Applaud 5
View profile

Avatar
Boost 1
Level 2
kunjalk3064084
Level 2

Like

1 like

Total Posts

8 posts

Correct Reply

0 solutions
Top badges earned
Boost 1
Applaud 5
View profile
kunjalk3064084
Level 2

25-01-2018

Hi,

I am trying to set values in some evars, props and events based on keywords present in the URL in the custom code of a direct call rule. so IF the URL contains xyz or abc, set

if (s.pageURL.indexOf("/xyz")>-1 || s.pageURL.indexOf("/abc")>-1)

{

s.event="event1";

s.prop5=s.eVar5=_satellite.getVar('test');

}

any idea on how to make these conditions work?

Replies

Avatar

Avatar
Boost 1
Level 2
kunjalk3064084
Level 2

Like

1 like

Total Posts

8 posts

Correct Reply

0 solutions
Top badges earned
Boost 1
Applaud 5
View profile

Avatar
Boost 1
Level 2
kunjalk3064084
Level 2

Like

1 like

Total Posts

8 posts

Correct Reply

0 solutions
Top badges earned
Boost 1
Applaud 5
View profile
kunjalk3064084
Level 2

29-01-2018

it is an s.t() rule

Avatar

Avatar
Affirm 250
Moderator
PratheepArunRaj
Moderator

Likes

296 likes

Total Posts

841 posts

Correct Reply

254 solutions
Top badges earned
Affirm 250
Contributor
Springboard
Shape 1
Validate 10
View profile

Avatar
Affirm 250
Moderator
PratheepArunRaj
Moderator

Likes

296 likes

Total Posts

841 posts

Correct Reply

254 solutions
Top badges earned
Affirm 250
Contributor
Springboard
Shape 1
Validate 10
View profile
PratheepArunRaj
Moderator

29-01-2018

Wherever you have events, rather than assigning the variable directly, use the below syntax.

s.event = "event1"

to

s.events = s.apl(s.events, "event1", ",", 2);

s.event = "event2"

to

s.events = s.apl(s.events, "event2", ",", 2);

Etc.

Avatar

Avatar
Validate 50
Level 8
SarahEOwen
Level 8

Likes

267 likes

Total Posts

408 posts

Correct Reply

17 solutions
Top badges earned
Validate 50
Validate 25
Validate 10
Validate 1
Ignite 1
View profile

Avatar
Validate 50
Level 8
SarahEOwen
Level 8

Likes

267 likes

Total Posts

408 posts

Correct Reply

17 solutions
Top badges earned
Validate 50
Validate 25
Validate 10
Validate 1
Ignite 1
View profile
SarahEOwen
Level 8

29-01-2018

Hi!

I had the same problem! In my Direct Call Rule, I set up an s.tl() call in the Adobe Analytics section of the rule. I have eVars and props set in the the Global Variables section and I have eVars, props, and events being set in the Custom Code. Yet none of my events in the Custom Code were being included in the analytics call, even though the s.events variable was being correctly valued.

This is how I fixed it

1) in the Custom Code, you can set your s.event in any fashion (either with your s.events=event2 or by using the append function of s.apl()).

2) add this line of code as the last line in your Custom Code --> s.linkTrackEvents=s.events;

And that is it! Save your rule, refresh the web page, go through the steps to trigger the Direct Call Rule, and you should see the events included in your analytics call

HAve a good day -

Sarah

Avatar

Avatar
Boost 5
Employee
Abhijeet_Mishra
Employee

Likes

30 likes

Total Posts

73 posts

Correct Reply

35 solutions
Top badges earned
Boost 5
Boost 3
Boost 25
Boost 10
Boost 1
View profile

Avatar
Boost 5
Employee
Abhijeet_Mishra
Employee

Likes

30 likes

Total Posts

73 posts

Correct Reply

35 solutions
Top badges earned
Boost 5
Boost 3
Boost 25
Boost 10
Boost 1
View profile
Abhijeet_Mishra
Employee

29-01-2018

Can you IM me the Site URL, you currently have it implemented on? I'd further like to debug the implementation and server calls.

Thanks.

Avatar

Avatar
Boost 1
Level 2
kunjalk3064084
Level 2

Like

1 like

Total Posts

8 posts

Correct Reply

0 solutions
Top badges earned
Boost 1
Applaud 5
View profile

Avatar
Boost 1
Level 2
kunjalk3064084
Level 2

Like

1 like

Total Posts

8 posts

Correct Reply

0 solutions
Top badges earned
Boost 1
Applaud 5
View profile
kunjalk3064084
Level 2

30-01-2018

update:

replaced s.pageURL with window.document.URL and the rule seems to work fine. however only the first part of the condition is being considered i.e. rules fires when URL contains /xyz but not when it contains /abc.

if (window.document.URL.indexOf("/xyz")>-1 || window.document.URL.indexOf("/abc")>-1)

is there any other way to implement an OR condition?

Avatar

Avatar
Boost 5
Level 4
Rydal_Williams
Level 4

Likes

22 likes

Total Posts

72 posts

Correct Reply

23 solutions
Top badges earned
Boost 5
Boost 3
Boost 10
Boost 1
Affirm 5
View profile

Avatar
Boost 5
Level 4
Rydal_Williams
Level 4

Likes

22 likes

Total Posts

72 posts

Correct Reply

23 solutions
Top badges earned
Boost 5
Boost 3
Boost 10
Boost 1
Affirm 5
View profile
Rydal_Williams
Level 4

30-01-2018

Could you send sample url's where these condition fail?