开发者

How do I inspect and interact with trails in KRL?

开发者 https://www.devze.com 2023-01-28 17:08 出处:网络
I have a trail that I\'m using to track app history in KRL. I\'m looking for an easy way to debug the trail, including seeing what is currently on the trail and clearing it.

I have a trail that I'm using to track app history in KRL. I'm looking for an easy way to debug the trail, including seeing what is currently on the trail and clearing it.

Is there an easy way to do 开发者_运维百科that in KRL?


The easiest way, for me, to see what is on the trail is to output it's contents to the browser console.

rule inspect_data_on_trail {
  select when pageview ".*"
  pre {
    visitedDomains = ent:visitedDomains;
  }
  {
    emit <|
      console.log(visitedDomains);
    |>;
  }
}

firebug output after running ruleset several times:

How do I inspect and interact with trails in KRL?

To clear entity variables including trails, I usually just write a rule that selects on a domain that isn't part of my app's experience and clear the varaibles when the app is run on that domain.

rule clear_everything {
  select when pageview "yahoo\.com"
  {
    notify("Cleared",":)") with sticky = true;
  }
  fired {
    clear ent:visitedDomains;
  }
}

Full example app:

ruleset a60x458 {
  meta {
    name "trail-debugging"
    description <<
      trail-debugging
    >>
    author "Mike Grace"
    logging on
  }

  rule put_data_onto_trail {
    select when pageview ".*"
    pre {
      domain = page:url("domain");
    }
    {
      notify("Thanks for visiting #{domain}","You visit has been recorded") with sticky = true;
    }
    fired {
      mark ent:visitedDomains with domain;
    }
  }

  rule inspect_data_on_trail {
    select when pageview ".*"
    pre {
      visitedDomains = ent:visitedDomains;
    }
    {
      emit <|
        console.log(visitedDomains);
      |>;
    }
  }

  rule clear_everything {
    select when pageview "yahoo\.com"
    {
      notify("Cleared",":)") with sticky = true;
    }
    fired {
      clear ent:visitedDomains;
    }
  }

}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号