# Identifying Users

> Beware, this guide requires basic coding and javascript knowledge.

> If you will be using personally identifiable information (PII) in your identifier, please include this in your privacy policy. HockeyStack bears no responsibility for holding this type of data.

It is just as important to know who your users are as what actions they’ve performed.

You can send both a unique identifier (usually email but can also be another id, username etc.) and any other custom properties (plan, role, company etc.) of your users to HockeyStack.

Bear in mind that using this method does not send a separate action to HockeyStack, it only updates the properties of that user.  For sending custom actions, see [tracking-custom-goals](https://docs.hockeystack.com/technical-details/tracking/tracking-custom-goals "mention").

## Sending Unique Identifier <a href="#block-cb1ddbc7c06548d19ad40f3041deed2a" id="block-cb1ddbc7c06548d19ad40f3041deed2a"></a>

In most implementations, the unique identifier is the user’s email address. You may also use another stable, unique value such as a user ID or username, as long as it consistently represents the same individual across sessions and systems.

### Method #1 <a href="#block-d62aa0f4a90843488ba1fa867763bea8" id="block-d62aa0f4a90843488ba1fa867763bea8"></a>

For this method, you would need HockeyStack to be already loaded in the website. Then, anywhere in your JavaScript, include:

```javascript
HockeyStack.identify('<your identifier>');
```

### Method #2 <a href="#block-c33ddea608c94d8c923ae00f768558f2" id="block-c33ddea608c94d8c923ae00f768558f2"></a>

Change the script to include `data-identity`.

#### Example for HTML <a href="#block-94781073d43645d4b1606b84174395b0" id="block-94781073d43645d4b1606b84174395b0"></a>

Add the highlighted section to your integration snippet:

```html
<script async data-identity="<your identifier>" data-apikey="<your api key>" data-cookieless src="https://cdn.jsdelivr.net/npm/hockeystack@latest/hockeystack.min.js"></script>
```

#### Example for other platforms <a href="#block-b96788f718a94a7abd41e8cc294c9a5f" id="block-b96788f718a94a7abd41e8cc294c9a5f"></a>

Add the highlighted line to your integration snippet:

```html
<script>
  var hsscript = document.createElement("script");
  hsscript.id = "hockeystackscript";
  hsscript.src = "https://cdn.jsdelivr.net/npm/hockeystack@latest/hockeystack.min.js";
  hsscript.async = 1;
  hsscript.dataset.apikey = "<your api key>";
  hsscript.dataset.cookieless = 1;
  hsscript.dataset.identity = <your identifier>;
  document.getElementsByTagName('head')[0].appendChild(hsscript);
</script>
```

## Sending Custom Properties <a href="#block-7d3443b4eae14bf98bd65cb8b0943033" id="block-7d3443b4eae14bf98bd65cb8b0943033"></a>

You can also send custom properties other than an identifier! It works similar to sending an identifier, but instead, you use an object:

```javascript
// assuming there is an object called `user` in your code that has the necessary data
HockeyStack.identify({
	plan: user.plan, // "Premium"
  revenue: user.revenue // 150.2
});

// or you can use the same identify call to both send a unique identifier and other custom properties
HockeyStack.identify(user.email,
	{
		plan: user.plan, // "Premium"
	  revenue: user.revenue // 150.2
	});
```

> You can send **Strings**, **Numbers** or **Booleans** as custom properties.

## ⚠️ Disclaimer <a href="#block-7dcce0af22e84fac8fd1df7516c7f14b" id="block-7dcce0af22e84fac8fd1df7516c7f14b"></a>

You should be very careful whether the HockeyStack object has been defined in the code at that point or not. If not defined, your users can get an error that would prevent the rest of the script (where you added the `identify` function) from executing.

In order to overcome this error:

1\. Or you can check whether the HockeyStack object is undefined.

```javascript
if (typeof HockeyStack !== 'undefined') HockeyStack.identify('<your identifier>');
```

2\. Or you can put a try-catch block around the identify function:

```sql
try { HockeyStack.identify('<your identifier>'); } catch(e) {}
```

3\. You can add another script that creates the HockeyStack buffer object:

```sql
<script>window.HockeyStack = window.HockeyStack || { identify: () => {}, goal: () => {} };</script>
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.hockeystack.com/technical-details/tracking/identifying-users.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
