# Email Tracking

Users tend to engage with emails even when they aren't engaged with your app. Thus, it's important to track how they interact with your emails.

Tracking clicks in emails works via redirects. You can use our client libraries to generate a redirect link.

<admonition type="info">

You can only create redirect links from your server-side application using one of Stream's API clients. Refer to our [API documentation](https://getstream.io/docs/) for more information on how to obtain the clients.

</admonition>

### Example

<codetabs>

<codetabs-item value="javascript" label="JavaScript">

```js
// the url to redirect to
const target_url = "http://mysite.com/detail";

// track the impressions and a click
const impression = {
  content_list: ["tweet:1", "tweet:2", "tweet:3"],
  user_data: "tommaso",
  location: "email",
  feed_id: "user:global",
};

const engagement = {
  content: "tweet:2",
  label: "click",
  position: 1,
  user_data: "tommaso",
  location: "email",
  feed_id: "user:global",
};

const events = [impression, engagement];
const tracking_url = client.client.createRedirectUrl(
  target_url,
  "tommaso",
  events,
);

// when the user opens the tracking url in their browser gets redirected to the target url the events are added to our analytics platform
```

</codetabs-item>

<codetabs-item value="python" label="Python">

```python
# the url to redirect to
target_url = 'http://mysite.com/detail'

# track the impressions and a click
impression = {
  'content_list': ['tweet:1', 'tweet:2', 'tweet:3'],
  'user_data': 'tommaso',
  'location': 'email',
  'feed_id': 'user:global'
}

engagement = {
  'content': 'tweet:2',
  'label': 'click',
  'position': 1,
  'user_data': 'tommaso',
  'location': 'email',
  'feed_id':
  'user:global'
}

events = [impression, engagement]
tracking_url = client.create_redirect_url(target_url, user_id, events)

# when the user opens the tracking url in their browser gets redirected to the target url
# the events are added to our analytics platform
```

</codetabs-item>

<codetabs-item value="php" label="PHP">

```php
$client = new GetStream\Stream\Client('{{ chat_api_key }}', '{{ api_secret }}');

// the url to redirect to
$targetUrl = 'http://my.application.com/page/';

$impression = [
 'content_list' => ['tweet:34349698', 'tweet:34349699', 'tweet:34349697'],
 'feed_id' => 'flat:tommaso',
 'location' => 'profile_page',
 'user_data' => ['id' => 'bubbles'],
 'label' => 'impression',
];

$engagement = [
  'content' => 'tweet:34349698',
  'feed_id' => 'flat:tommaso',
  'location' => 'profile_page',
  'user_data' => ['id' => 'frank'],
  'label' => 'click',
];

$events = [$impression, $engagement];
$trackingUrl = $client->createRedirectUrl($targetUrl, $events);

// when the user opens the tracking url in their browser gets redirected to the target url
// the events are added to our analytics platform
```

</codetabs-item>

<codetabs-item value="java" label="Java">

```java
// the URL to direct to
URL targetURL = new URL("http://mysite.com/detail");

// track the impressions and a click
List<impression> impressions = Lists.newArrayList(Impression.builder()
    .contentList(new Content("tweet:1"),
        new Content("tweet:2"),
        new Content("tweet:3"))
    .userData(new UserData("tommaso", null))
    .location("email")
    .feedID("user:global")
    .build());
List<engagement> engagements = Lists.newArrayList(Engagement.builder()
    .content(new Content("tweet:2"))
    .label("click")
    .position(1)
    .userData(new UserData("tommaso", null))
    .location("email")
    .feedID("user:global")
    .build());

// when the user opens the tracking URL in their browser gets redirected to the target URL
// the events are added to our analytics platform
URL trackingURL = client.analytics().createRedirectURL(targetURL, impressions, engagements);</engagement></impression>
```

</codetabs-item>

<codetabs-item value="go" label="Go">

```go
// the URL to direct to
targetURL := "http://mysite.com/detail"

// track the impressions and a click
impression := ImpressionEventsData{}.
	WithForeignIDs("tweet:1", "tweet:2", "tweet:3").
	WithUserData(NewUserData().String("tommaso")).
	WithLocation("email").
	WithFeedID("user:global")

engagement := EngagementEvent{}.
	WithForeignID("tweet:2").
	WithLabel("click").
	WithPosition(1).
	WithUserData(NewUserData().String("tommaso")).
	WithLocation("email").
	WithFeedID("user:global")

trackingURL, err := client.Analytics().RedirectAndTrack(targetURL, impression, engagement)
if err != nil {
	panic(err)
}
// when the user opens the tracking URL in their browser gets redirected to the target URL
// the events are added to our analytics platform
```

</codetabs-item>

</codetabs>

In the code above, when a user clicks the tracking URL, they are re-directed to the specified target URL. During the re-direct, Stream tracks the impressions and engagement events you specified.


---

This page was last updated at 2026-03-16T10:38:03.841Z.

For the most recent version of this documentation, visit [https://getstream.io/activity-feeds/docs/go-golang/v2/analytics_email/](https://getstream.io/activity-feeds/docs/go-golang/v2/analytics_email/).