<commit_before># HuggyEvents

HuggyEvents are a special category of events send by bot apps through regular [user events](https://github.com/GhostWording/PublicDocumentation/blob/master/API/Sections/useractions.md).

As it's a regular userevent, the payload is exactly the same as defined in user events page, we'll only discuss here about the values of these properties.

For publishing the event you should send a `POST` TO `http://gw-usertracking.azurewebsites.net/userevent/batch` with the following `JSON` payload:

    {
        "ActionType":"HuggySequenceStart",
        "ActionLocation":"",
        "TargetType":"id of seq",
        "TargetId":"Page",
        "TargetParameter":null,
        "AreaId":"bot name",
        "UserId":null,
        "DeviceId":"4e115472",
        "RecipientId":"",
        "LanguageCode":"fr",
        "ClientTime":"2016-01-11T15:56:57.2233538Z",
        "FacebookId":"2xxxx",
        "VersionNumber":1,
        "OsType":"app os",
        "ExperimentId":3,
        "VariationId":4,
        "IsNewInstall":true,
        "IntentionId":""
        "Last":0
    }
    
## Exemples of payloads
(for brievety, I only put here useful fields for the event, the rest is as usual)

* I start showing the user the sequence "HowAreYou", that is on position 30 on master file "mybotmaster.json" within the group "Survey", for the bot named `testBot` :

    
      {
        "ActionType":"HuggySequenceStart",
        "AreaId":"testBot",
        "ActionLocation":"mybotmaster-30",
        "Context":"HowAreYou",
        "Last":0,
        "TargetId":"HowAreYou",
        "TargetType":"Survey",
        "TargetParameter":"Hello, world! how are you?",
        "RecipientId":0
      }


* (still in HowAreYou sequence), After executing the first node in the sequence tree, I finished by executing commands and asking something to the user. After the user selection, we'll start executing the command selected and send a `HuggySequenceNext` event:

    
      {
        "ActionType":"HuggySequenceNext",
        "AreaId":"testBot",
        "ActionLocation":"mybotmaster-30",
        "Context":"HowAreYou",
        "Last":0,
        "TargetId":"ImFine",
        "TargetType":"Survey",
        "TargetParameter":"1",
        "RecipientId":1
      }
    
    
## Details
    
The valuable properties for huggy events are defined as this:
    
* **ActionType**:
  * it defines the type of the action for the event
  * it can be HuggyConversationStart | HuggySequenceStart | HuggySequenceNext (...)
* **AreaId**: the name of the bot you're executing
* **ActionLocation**: 
  * in information about the reference to this sequence (which master file reference this sequence ? and in what order within?)
  * it's a combination of these 2 info in one field separated by a dash -> `"{masterFile}-{order}"`
* **Context**: SequenceId. In order to reconstitute the executing path we need to be able to link events that happened during the execution of the sequence, that's why you need to keep in this context field the Id of the current sequence
* **Last**: 
  * if the element is the last element of the sequence tree, then it's marked `Last=1`, if not then it's `0`. 
  * in a simpler way, then if the element is a node (an element with children) then it's 0, if its a Leaf then its a terminal element and value is 1.
* **TargetId**: contains the id of the current executing element in the tree<commit_msg>Update huggyEvents.md<commit_after># HuggyEvents

HuggyEvents are a special category of events send by bot apps through regular [user events](https://github.com/GhostWording/PublicDocumentation/blob/master/API/Sections/useractions.md). We'll only discuss here the specificities of these events

The objective of the HuggyEvents is to see the path taken by the users, to see when they stop and globally what are the best sequences. For that we need to see when a sequence is presented to a user, when a user interacts with it and if he finishes it.

* **[Presented]**: a sequence is presented when you start executing it and start showing the first elements to the user. You'll send an event with `ActionType=HuggySequenceStart`. 
* **[Started]**: a sequence is started when the user reacts (click/select) for the first time to something in the sequence (a menu is shown). You'll send an event with `ActionType=HuggySequenceNext` and specify the **Recipient=1** (we re-use that field **RecipientId** just to not create a new one, but that means _number of interractions with the user_)
* **[Finished]**: a sequence is finished when you arrive at the end of the sequence in a leaf and that there is nothing more to show. You'll send an event with `ActionType=HuggySequenceNext`, specify the number of interraction and set the field `Last=1`
* **other interactions**: between the start and finish you're supposed to send an `ActionType=HuggySequenceNext` each time a user clicks on something to continue (specifying the Nth of times the user did something in this sequence).

Please refer to the details below for the other specific values of the event.


## Exemples of payloads
(for brievety, I only put here useful fields for the event, the rest is as usual)

* I start showing the user the sequence "HowAreYou", that is on position 30 on master file "mybotmaster.json" within the group "Survey", for the bot named `testBot` :

    
      {
        "ActionType":"HuggySequenceStart",
        "AreaId":"testBot",
        "ActionLocation":"mybotmaster-30",
        "Context":"HowAreYou",
        "Last":0,
        "TargetId":"HowAreYou",
        "TargetType":"Survey",
        "TargetParameter":"Hello, world! how are you?",
        "RecipientId":0
      }


* (still in HowAreYou sequence), After executing the first node in the sequence tree, I continue by executing commands and asking something to the user. After the user selection, we'll start executing the command selected and send a `HuggySequenceNext` event:

    
      {
        "ActionType":"HuggySequenceNext",
        "AreaId":"testBot",
        "ActionLocation":"mybotmaster-30",
        "Context":"HowAreYou",
        "Last":0,
        "TargetId":"ImFine",
        "TargetType":"Survey",
        "TargetParameter":"1",
        "RecipientId":1
      }
    
    
* (still in HowAreYou sequence). in the previous node of the sequence I shown a menu, the user click on an item. as this one is the last one of the sequence I'll send a `HuggySequenceNext` event with `Last=1` and `RecipientId=2` (because this step result is the second interaction of the user with the sequence).


      {
        "ActionType":"HuggySequenceNext",
        "AreaId":"testBot",
        "ActionLocation":"mybotmaster-30",
        "Context":"HowAreYou",
        "Last":1,
        "TargetId":"ILikeCookies",
        "TargetType":"Survey",
        "TargetParameter":"1",
        "RecipientId":2
      }
    

## Details
    
The valuable properties for huggy events are defined as this:
    
* **ActionType**:
  * it defines the type of the action for the event
  * it can be HuggyConversationStart | HuggySequenceStart | HuggySequenceNext (...)
* **AreaId**: the name of the bot you're executing
* **ActionLocation**: 
  * in information about the reference to this sequence (which master file reference this sequence ? and in what order within?)
  * it's a combination of these 2 info in one field separated by a dash -> `"{masterFile}-{order}"`
* **Context**: SequenceId. In order to reconstitute the executing path we need to be able to link events that happened during the execution of the sequence, that's why you need to keep in this context field the Id of the current sequence
* **Last**: 
  * if the element is the last element of the sequence tree, then it's marked `Last=1`, if not then it's `0`. 
  * in a simpler way, then if the element is a node (an element with children) then it's 0, if its a Leaf then its a terminal element and value is 1.
* **TargetId**: contains the id of the current executing element in the tree
{'fraction_non_alphanumeric': 0.0963055729492799, 'fraction_numerical': 0.009267376330619912, 'mean_word_length': 3.451505016722408, 'pattern_counts': {'":': 64, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1975285', 'n_tokens_mistral': 2247, 'n_tokens_neox': 2112, 'n_words': 955}