Expand my Community achievements bar.

SOLVED

DTM keypress question

Avatar

Level 2

Hi people, new to DTM.

I am trying to setup a keypress condition which only fires if keyCode is X. How do I setup the rule properly for the keyCode check?

1 Accepted Solution

Avatar

Correct answer by
Level 2

Alright, I managed to "hack" it up so it works.

Summary of issues:

1) Expose KeyDown as rule condition

2) In the script, when defining the condition function, DTM should pass the same variable that is passed through to the ruleMatch function.

ie. 

            var h = b.find(o, function(e) {
                try {
                    return !e.call(i, n, u)...

e is the condition function which is called with 3 variables. But on init, the condition is only declared as a simple function()

            conditions: [function() {

It should take in 3 variables too so that custom rule condition can make use of the 3 variables for customized tracking.

The below is what I used in the pageload rule to run a custom "hack" for my rule. My event rule is I want to track left arrow key press when a pop up is in the dom (media gallery scenario)

_satellite.registerEvents($("body")[0], ["keydown"])

_satellite.rules[0].conditions[0] = function(i, n, u){console.log(i); return $("popup").length>0&&37===i.keyCode;};

_satellite.rules[0].event = "keydown"

View solution in original post

4 Replies

Avatar

Level 10

Hi There,

Thanks for reaching out to Adobe Community.

Please see if the below article helps:

http://microsite.omniture.com/t2/help/en_US/dtm/t_rules_event_conditions.html

Thanks!

Avatar

Level 2

Nope, it doesn't help. I basically want to use DTM to track if the user presses a particular key. 

Avatar

Level 2

I also need the KeyDown instead of KeyPress as keypress doesn't capture all the key presses.

Avatar

Correct answer by
Level 2

Alright, I managed to "hack" it up so it works.

Summary of issues:

1) Expose KeyDown as rule condition

2) In the script, when defining the condition function, DTM should pass the same variable that is passed through to the ruleMatch function.

ie. 

            var h = b.find(o, function(e) {
                try {
                    return !e.call(i, n, u)...

e is the condition function which is called with 3 variables. But on init, the condition is only declared as a simple function()

            conditions: [function() {

It should take in 3 variables too so that custom rule condition can make use of the 3 variables for customized tracking.

The below is what I used in the pageload rule to run a custom "hack" for my rule. My event rule is I want to track left arrow key press when a pop up is in the dom (media gallery scenario)

_satellite.registerEvents($("body")[0], ["keydown"])

_satellite.rules[0].conditions[0] = function(i, n, u){console.log(i); return $("popup").length>0&&37===i.keyCode;};

_satellite.rules[0].event = "keydown"