Expand my Community achievements bar.

SOLVED

Issue: null value of manually assigned property is treated "null" string

Avatar

Level 2

I tried to create event rule for click tracking of "a" tag which has specific property, but the rule fired even on all other links.
I investigated it and found SL.propertiesMatch function has a procedure might cause unintended behavior easily.

I intend to assign propery "data-tracking" with any value at "condition" area in DTM and set "data-tracking" = .* (RegExp).
Then I clarified it on staging website, every time i clicked anchor links, that rule fired.

When links which does NOT have specified property are clicked, DTM searches "data-tracking" property and returns null.
Then it checks if null(null) matches /.*/i (RegExp). It must be failed, but it returns TRUE because RegExp.test() method treats passed null as a string "null"!! 

SL.propertiesMatch = function(e, t) { if (e) for (var n in e) if (e.hasOwnProperty(n)) { var i = e[n] , a = SL.getElementProperty(t, n); if ("string" == typeof i && i !== a) return !1; if (i instanceof RegExp && !i.test(a)) return !1 } return !0 }
1 Accepted Solution

Avatar

Correct answer by
Level 10

Hi Kunihiro ,

 One of the work around for the problem would be to create Negative look-ahead regular expression like ^((?!null).)*$  (RegEx)  such that "null" values are rejected however the only thing to remember is that this expression would also reject the value "null-xcxcxc" .

Also, Generally it is recommended to check whether a string is null or not before passing it to regex test function Hence I would suggest to write a custom rule condition for your use case like below to avoid missing out on any cases

Thanks & Regards

Parit Mittal

View solution in original post

3 Replies

Avatar

Correct answer by
Level 10

Hi Kunihiro ,

 One of the work around for the problem would be to create Negative look-ahead regular expression like ^((?!null).)*$  (RegEx)  such that "null" values are rejected however the only thing to remember is that this expression would also reject the value "null-xcxcxc" .

Also, Generally it is recommended to check whether a string is null or not before passing it to regex test function Hence I would suggest to write a custom rule condition for your use case like below to avoid missing out on any cases

Thanks & Regards

Parit Mittal

Avatar

Level 10

Hi,

Is the above issue resolved ?. If yes, yo can go ahead and mark the above answer as correct.

Thanks & Regards

Parit Mittal

Avatar

Level 2

I set "a[data-tracking]" to  as a workaround.
I think your workaround also works well but it's a little bit more complicated than css selector.

It'd be helpful if this fix is applied.

Best regards,
Kunihiro Sasaki