User Identification How Hawk tells your users apart

Choose How to Identify Users

If your site allows users to log in to individual accounts, your analytics results with Hawk will greatly improve if we can identify which user is which. User identification allows us to associate multiple sessions, from different devices and ip addresses, with the same user. There are two ways we can do this:

Manual User Identification

Hawk User Identification: Manual
Manual User Identification

The Hawk code creates a function you can call manually to alert us when a user logs in or out. It looks like this:

hawk.setUser({
  email: 'joe@example.com',
  name: 'Joe Smith',
  phone: '555-555-1212',
  uniqueId: '12345',
  username: 'joesmith',
})


And when a user logs out:

hawk.setUser(null)


The only required field is uniqueId, which we use to differentiate between users. We recommend that you use the unique id of the user from your database.

Automatic User Identification

Hawk User Identification: Automatic
Automatic User Identification

Hawk can also automatically identify users. We do this by hooking into window.fetch and window.XMLHttpRequest to look at your site’s traffic (for technical details, see here.)
If you let us know what backend endpoint your frontend code calls to retrieve the currently logged in user, we can find the user’s information without you having to write any extra code.

How it Works

You provide us with a set of rules that we’ll use to distinguish your site’s user information network traffic from all the rest.
All vs. Any This is the difference between logical and and logical or. You might use Any to let us know about multiple different requests that contain user information. All allows you to provide more criteria to distinguish the user information requests from all the rest.
(+) and (-) The plus and minus buttons add and remove criteria. Clicking the () button allows you to add a new branch of logic with its own All/Any operator.

Criteria
Endpoint Criteria Dropdown
Endpoint Criteria Dropdown
  • hostname: The domain name of your server
  • method: The HTTP method of the request
  • Page hostname: This filters on the hostname of the user’s location.
  • path: The part of the URL after the domain name
  • url: The entire URL of the response, including protocol, domain name and path
  • Page url: This filters on the url of the user’s location.
  • status: The HTTP status code of the response
  • responseJSON: This allows you to specify a particular JSON structure in the server’s response. If that structure is not present in the response, this criteria will not match. For example, a rule like responseJSON : name.first : is : David would match when the JSON has the structure:

    {
      ...,
      "name": {
        ...,
        "first": "David",
        ...,
      },
      ...,
    }
    

For a complete list of filter criteria available in Hawk, see here.

Comparators
Endpoint Comparator Dropdown

(Note: Not all comparators are valid for all filter criteria.)

  • Is: Matches when the specified string and the result are identical.
  • Is Not: Matches when the specified string and the result are different.
  • Starts With: Matches when the specified string appears at the beginning of the result.
  • End With: Matches when the specified string appears at the end of the result.
  • Matches: Allows you to enter a regular expression. Matches if the regular expression matches.
  • Does Not Match: Allows you to enter a regular expression. Matches if the regular expression does not match.
  • GT: Greater than. Only used for numbers.
  • LT: Less than. Only used for numbers.
  • Between: Allows you to supply two numbers. Matches when the result is between them.
  • Field.Name: Only used for the resoponseJSON criterion. This specifies a location within the response JSON to match.
  • Is Truthy: Matches when the result is truthy.
  • Is Falsy: Matches when the result is falsy.

Did you find this article helpful?