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
Bedrock Mission!

Learn more

View all

Sign in to view all badges

Tip: correct way to use "this"'s custom attribute with %...% notation

analytics_union
Level 4
Level 4

Sharing a tip that I hope will make your life better.

When using %this....% with a custom attribute, don’t use quote marks. I.e. use %this.getAttribute(custom-attribute)% without quote marks, not %this.getAttribute("custom-attribute")%.

(BTW this goes against my JavaScript sensibilities.)

How I discovered this:

For a link click, I want to set an eVar to the value of the link’s data-foo attribute. (My link definitely has a data-foo attribute with a valid string value.)

Round 1:

In the rule’s AA - Set Variables action, in the form, I set my eVar’s value to %this.getAttribute("data-foo")%. In the custom code, for sanity sake, I set another eVar to _satellite.getVar("data-foo"), with the appropriate linkTrackVars.

--> Result: my original eVar is set with the string "null", my custom code eVar gets data-foo’s string value.

Round 2:

In the AA - Set Variables form, I use %this.data-foo%.

--> Result: my original eVar is not set at all, my custom code eVar gets data-foo’s string value.

Round 3:

In the AA - Set Variables form, I use %this["data-foo"]%.

--> Result: my original eVar is set with the string "%this[\"data-foo\"]%", my custom code eVar gets data-foo’s string value.

Round 4:

In the AA - Set Variables form, I use %this.getAttribute(data-foo)% without quote marks in the argument.

--> Result: my original eVar gets data-foo’s string value, my custom code eVar gets data-foo’s string value.

0 Replies