Expand my Community achievements bar.

DTM Rules

Avatar

Level 3

Hi,

Hope someone can assist with query I have. I'm fairly new to DTM so bear with me.

I have the following 4 sample URLs. I'm trying to fire off a pageload rule to set the page name depended on the parameters present on the URL.

URL 1

?actionUrl=/Member/Beneficiaries/Index&plancode=HS

for the above I'm trying to set the page name to "Member Beneficiaries | Index"

URL 2

?actionUrl=/Member/Beneficiaries/Index&plancode=HS&trackid-1

for the above I'm trying to set the page name to "Member Beneficiaries | Trackid"

URL3

?actionUrl=/Member/MemberProfile/Index&plancode=HS

for the above I'm trying to set the page name to "Member Profile| Index"

URL4

?actionUrl=/Member/MemberProfile/Index&plancode=HS&trackid-1

for the above I'm trying to set the page name to "Member Profile | Trackid"

I tried to use the include path condition but it didn't work. Is there any other method I can use?

Please advise.

cheers,

Winston

5 Replies

Avatar

Level 10

Hi Winston,

The easiest way that comes to mind is a page load rule for each of the scenarios you've described. Can you post screenshots of the rule you created with the include path condition?

Thanks,
Jantzen

Avatar

Level 3

HI Jantzen,

Thank you for looking into this for me.

Below is path condition for ?actionUrl=/Member/Beneficiaries/Index&plancode=HS&trackid-1

1411465_pastedImage_0.png

Below is path condition for ?actionUrl=/Member/Beneficiaries/Index&plancode=HS

1411466_pastedImage_1.png

The rule seems to fire as expected for the above,

1411468_pastedImage_2.png

However, it doesn't work or ?actionUrl=/Member/Beneficiaries/Index&plancode=HS&trackid-1

It still sets the page name as per the other rule.

1411475_pastedImage_3.png

So wondering, what other methods I can try.

regards,

Winston

Avatar

Level 9

A condition using Path (include|exclude) is a substring ("contains") match.  (sidenote: actually DTM performs a regex match against the value, even when you have Regex option turned off. Not relevant for your current values, but keep this in mind for future reference: you need to escape special regex chars if you want to use Path (include|exclude), even if you have regex option disabled!)

So, in your 1st rule, your condition is for path contains "actionUrl=/Member/Beneficiaries/Index&plancode=HS"

And in the 2nd rule, your condition is for path contains "actionUrl=/Member/Beneficiaries/Index&plancode=HS&trackid-1". 

So if your URL includes that "&trackid=1" part, then your 1st rule won't trigger.  But if it does not, then both rules trigger, and the 2nd one fired will win. And it sounds like in your case, rule #1 is executing after rule #2.

DTM doesn't officially have a way to enforce order of operations on a rule level, other than the 4 "Trigger at" types (top of page, bottom of page, dom ready, window load) .  For multiple rules for a given "Trigger at" type, internally it just goes down the list. However, the order doesn't always reflect the order in the interface. (Once upon a time you could control the order by how you named the rules (e.g. "foo1" will execute before "foo2" because it sorts higher alphabetically) but this is no longer the case. I'm not entirely sure what ultimately determines list order now.. but point is, there is no official way to enforce order of operations of rules.)

Before getting into solving for this, I want to make an additional note that creating a condition like what you've done is not stable.  The values you are evaluating are part of the query string (location.search).  Well, query parameters can appear in any order.  So for example, your (full) URL with the following query parameters:

actionUrl=/Member/Beneficiaries/Index&plancode=HS

is functionally identical to your (full) URL with the query parameters with swapped order:

plancode=HS&actionUrl=/Member/Beneficiaries/Index

The reason I bring this up is because your current rule conditions would fail on the latter scenario, which is almost certainly not what you want.  So in practice, you should only use Path (includes|excludes) to look at the URL path (location.pathname) part of the URL, not the query string (location.search). (But actually, DTM's Path references (location.pathname+location.search), which is a bit misleading - and also can lead to false positives in some cases. So in practice, I create a data element of js object type that returns only location.pathname and use that instead, because there are almost no stable use cases for matching against location.pathname+location.search together)

To solve for all of this, instead of using Path criteria, you should use Parameter criteria to look for individual query params. This way it won't matter which order they appear in the URL.  Also, this will help weed out potential false positives since the Parameter criteria type specifically parses the query string component of the URL.  This will solve for your plancode and actionUrl query parameters, but not for trackid-1.

DTM does not have a built-in way to say "this query parameter does not exist" (what you want for your first rule).  Nor does it have a way to say "This query parameter is found but it does not have a value" (what you want for your second rule). The only solution for this part is to write your own javascript code, using Data > Custom criteria.

For your 1st rule, you want it to trigger if trackid-1 does not exist at all, so you can do this:

return !location.search.match(/[?&]trackid-1(=[^&#]*)?([&#]|$)/);

For your 2nd rule, you want it to trigger if it exists (even if it has no value, so you can do this:

return location.search.match(/[?&]trackid-1(=[^&#]*)?([&#]|$)/);

Note: Both regexes are the same. They return a value if trackid-1 is found in location.search, regardless of position or if it has a value. The difference between the 1st and 2nd rule code is in the 1st rule's code, there is a ! in front of location , which negates the match's returned value.  So on the first rule, if it is found you want to return false, and in the 2nd rule you want it to return true.

So, putting it all together, both of your rules should have a total of 3 conditions and look almost exactly alike, except for one "!" in the custom code:

Page Load Rule #1 to match for

?actionUrl=/Member/Beneficiaries/Index&plancode=HS

Where URL Parameter actionUrl equals "/Member/Beneficiaries/Index"

AND URL Parameter where plancode equals "HS"

AND where URL Parameter trackid-1 does not exist

chrome_2018-02-06_11-02-03 - Copy.png

Page Load Rule #2 to match for ?actionUrl=/Member/Beneficiaries/Index&plancode=HS&trackid-1

Where URL Parameter actionUrl equals "/Member/Beneficiaries/Index"

AND URL Parameter where plancode equals "HS"

AND where URL Parameter trackid-1 exists

chrome_2018-02-06_11-06-23 - Copy.png

Avatar

Level 3

Hi Josh,

This is awesome!!

Thank you for the input. Great learning and will be sure to keep this in mind for future scenarios.

cheers,

Winston