# Segment Tracking Theme Component

**URL:** https://meta.discourse.org/t/segment-tracking-theme-component/133335
**Category:** Theme component
**Tags:** end-of-life
**Created:** [November 13, 2019, 8:10pm UTC](https://meta.discourse.org/t/segment-tracking-theme-component/133335 "2019-11-13T20:10:59Z")
**Posts on this page:** 17
**Page:** 1

<div class="post-metadata">

### Author: ![simon](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/simon/32/339122_2.png) [@simon](https://meta.discourse.org/u/simon)
#### Post date: [November 13, 2019, 8:10pm UTC](https://meta.discourse.org/t/segment-tracking-theme-component/133335/1 "2019-11-13T20:10:59Z")

</div>

> **⚠ The repository was archived by the owner on Jun 25, 2025**

This theme component allows you to send data about your site’s usage to [Segment](https://segment.com/).

The component supports calling `segment.identify` when a user first logs on to the site. For site’s using SSO, you can either send the user’s Discourse ID, or their `external_id` to Segment. The component allow you to track views of the Discourse latest, categories, category, tag, and topic pages. It also allows you to track topic and post creation, likes, flags, and bookmarks.

### Installation

Follow the [Installing a theme or theme component](https://meta.discourse.org/t/how-do-i-install-a-theme-or-theme-component/63682) guide to install the component. Use `https://github.com/scossar/discourse-segment-theme-component` to install it directly from its Git repository. You can also download it from [here](https://github.com/scossar/discourse-segment-theme-component).

### Configuration

Add your Segment Write Key to the `segment write key` setting. Then select which events you would like to track:

 ![image](https://global.discourse-cdn.com/meta/original/3X/4/8/481b41a3129904144bf3b3e973e636fec8f4780e.png)

The component extends your site’s content security policy to add `https://cdn.segment.com/analytics.js/`.

Let me know of any issues you run into with the component, or if there are ways that the data sent to Segment could be improved.

---

<div class="post-metadata">

### Author: ![ghufransyed](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/ghufransyed/32/187888_2.png) [@ghufransyed](https://meta.discourse.org/u/ghufransyed)
#### Post date: [September 8, 2020, 12:36am UTC](https://meta.discourse.org/t/segment-tracking-theme-component/133335/2 "2020-09-08T00:36:59Z")

</div>

Thanks for building this, this is awesome! Does it also send data on anonymous users?

---

<div class="post-metadata">

### Author: ![simon](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/simon/32/339122_2.png) [@simon](https://meta.discourse.org/u/simon)
#### Post date: [September 8, 2020, 5:17pm UTC](https://meta.discourse.org/t/segment-tracking-theme-component/133335/3 "2020-09-08T17:17:23Z")

</div>

> [@ghufransyed](#):
>
> Does it also send data on anonymous users?

Calls to the Segment `page` method are made for anonymous users, but the Segment `identify` method is only called for logged in users.

---

<div class="post-metadata">

### Author: ![paigen11](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/paigen11/32/229055_2.png) [@paigen11](https://meta.discourse.org/u/paigen11)
#### Post date: [August 3, 2021, 9:57pm UTC](https://meta.discourse.org/t/segment-tracking-theme-component/133335/4 "2021-08-03T21:57:16Z")

</div>

Hello there!

I know I am extremely late to this party, but I have a request I was hoping you might be able to accommodate.

Could you add, in addition to the user ID number the user email address when users are logged in to Discourse?

In Segment I’m trying to combine Discourse data with user data for what could be the same user on my company’s website to understand which users are checking discourse and checking out the website, but I can’t match up users right now because the Discourse user ID doesn’t match the website’s user ID.

If I was able to match them up when the email address was the same from Discourse and the site, that would be so helpful.

Could this be possible, please?

---

<div class="post-metadata">

### Author: ![Justin\_Gage](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/justin_gage/32/230057_2.png) [@Justin\_Gage](https://meta.discourse.org/u/Justin_Gage)
#### Post date: [August 6, 2021, 2:41pm UTC](https://meta.discourse.org/t/segment-tracking-theme-component/133335/5 "2021-08-06T14:41:44Z")

</div>

Amazing plugin, thanks @simon! I’ve been using it for a few months, and I’m finding that it misses `topic_created` events every now and then. I can’t seem to identify any patterns in these misfires, so I figured I’d write in here. Any ideas? Are there any logs I can check for errors?

---

<div class="post-metadata">

### Author: ![simon](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/simon/32/339122_2.png) [@simon](https://meta.discourse.org/u/simon)
#### Post date: [August 6, 2021, 9:34pm UTC](https://meta.discourse.org/t/segment-tracking-theme-component/133335/6 "2021-08-06T21:34:17Z")

</div>

> [@paigen11](#):
>
> Could you add, in addition to the user ID number the user email address when users are logged in to Discourse?

This is technically possible. I have some security and privacy concerns about adding the email address to the payload though. I’ll give it some thought and ask the Discourse team to see what they think. If the email address is added to the payload, there will be a theme setting for it that defaults to not including the email address.

> [@Justin\_Gage](#):
>
> I’m finding that it misses `topic_created` events every now and then. I can’t seem to identify any patterns in these misfires

I’ll look into this. If you do find a pattern to it, please let me know.

I’ll try to find the time next week to test out the component and make some updates to it. When that’s been done, I’ll move it from my personal GitHub repo to the Discourse GitHub repo.

---

<div class="post-metadata">

### Author: ![Justin\_Gage](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/justin_gage/32/230057_2.png) [@Justin\_Gage](https://meta.discourse.org/u/Justin_Gage)
#### Post date: [August 6, 2021, 9:46pm UTC](https://meta.discourse.org/t/segment-tracking-theme-component/133335/7 "2021-08-06T21:46:12Z")

</div>

Thank you @simon, really appreciate that 🙂

---

<div class="post-metadata">

### Author: ![paigen11](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/paigen11/32/229055_2.png) [@paigen11](https://meta.discourse.org/u/paigen11)
#### Post date: [August 9, 2021, 1:24pm UTC](https://meta.discourse.org/t/segment-tracking-theme-component/133335/8 "2021-08-09T13:24:12Z")

</div>

@simon I hear you and agree about the security concerns, however, I am an admin of the Discourse I’m pulling this data from, so I could find the same user emails simply by taking the provided ID and going into the user records to connect the ID to the email address that way. It’s already available, albeit manually.

Additionally, though after speaking to others in my org, we may end up just waiting until we have Oauth set up so that our users will have to use the same ID logging in to our system and the Discourse system.

Regardless I think it would still be a nice feature to have - in case a solution like that isn’t available to someone else in the community.

Thanks

---

<div class="post-metadata">

### Author: ![simon](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/simon/32/339122_2.png) [@simon](https://meta.discourse.org/u/simon)
#### Post date: [August 10, 2021, 12:08am UTC](https://meta.discourse.org/t/segment-tracking-theme-component/133335/10 "2021-08-10T00:08:36Z")

</div>

> [@paigen11](#):
>
> Additionally, though after speaking to others in my org, we may end up just waiting until we have Oauth set up so that our users will have to use the same ID logging in to our system and the Discourse system.

This seems like the ideal approach. The Segment theme component could be updated to add an option to include the `provider_uid` that is supplied by your Auth provider.

I’m glad you brought this up. The Segment tracking component currently has an option to add the user’s `external_id` for site’s that are using [DiscourseConnect](https://meta.discourse.org/t/13045?silent=true). Looking at it now, I see that it is using the old settings name for for [DiscourseConnect](https://meta.discourse.org/t/13045?silent=true) - it is checking to see if the `enable_sso` setting is enabled. That needs to be changed to `enable_discourse_connect`. I’ll get that fixed tomorrow.

---

<div class="post-metadata">

### Author: ![paigen11](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/paigen11/32/229055_2.png) [@paigen11](https://meta.discourse.org/u/paigen11)
#### Post date: [August 10, 2021, 1:19pm UTC](https://meta.discourse.org/t/segment-tracking-theme-component/133335/11 "2021-08-10T13:19:50Z")

</div>

Thanks so much, a `provider_uid` field would be fantastic to have - that should make it possible for us to associate actions by user across our site and Discourse both after they’re sent to Segment.

I appreciate it.

---

<div class="post-metadata">

### Author: ![simon](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/simon/32/339122_2.png) [@simon](https://meta.discourse.org/u/simon)
#### Post date: [August 13, 2021, 9:04pm UTC](https://meta.discourse.org/t/segment-tracking-theme-component/133335/12 "2021-08-13T21:04:21Z")

</div>

I have fixed the issue with tracking users based on their `external_id` for the case where [DiscourseConnect](https://meta.discourse.org/t/13045?silent=true) is enabled as the authentication provider for the Discourse site.

So far I’ve been unable to track down what could be causing topic creation to sometimes not be tracked. It is working for me without any issues.

I’ve updated the name that is used for the Topic Bookmarked event. Previously the event name that was being sent to Segment was “Thread Bookmarked.” I don’t remember the reasoning for that. Hopefully changing the event name to “Topic Bookmarked” doesn’t cause issues with anyone’s analytics.

---

<div class="post-metadata">

### Author: ![Cody\_W\_Tucker](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/cody_w_tucker/32/231454_2.png) [@Cody\_W\_Tucker](https://meta.discourse.org/u/Cody_W_Tucker)
#### Post date: [August 18, 2021, 9:10pm UTC](https://meta.discourse.org/t/segment-tracking-theme-component/133335/13 "2021-08-18T21:10:43Z")

</div>

When I checked the debugger screen in Segment, all that was sent on the identify call was a User Id and IP address. Can an email address also be passed with the identify call?

---

<div class="post-metadata">

### Author: ![simon](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/simon/32/339122_2.png) [@simon](https://meta.discourse.org/u/simon)
#### Post date: [August 18, 2021, 9:12pm UTC](https://meta.discourse.org/t/segment-tracking-theme-component/133335/14 "2021-08-18T21:12:58Z")

</div>

> [@Cody\_W\_Tucker](#):
>
> Can an email address also be passed with the identify call?

> [@paigen11](#):
>
> Could you add, in addition to the user ID number the user email address when users are logged in to Discourse?

That’s two requests to have email addresses passed with the identify call. I’ll see what can be done about that.

---

<div class="post-metadata">

### Author: ![simon](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/simon/32/339122_2.png) [@simon](https://meta.discourse.org/u/simon)
#### Post date: [August 18, 2021, 10:45pm UTC](https://meta.discourse.org/t/segment-tracking-theme-component/133335/15 "2021-08-18T22:45:18Z")

</div>

I went ahead and added an `include user email` setting:

 ![image](https://global.discourse-cdn.com/meta/original/3X/d/0/d0bec12e4b667b3dffa23937614aa1cd08677511.png)

When enabled, the user’s email address will be passed with the `identify` call. If you update the theme component on your Discourse site to its most recent version, that setting will be available to you.

A minor issue I found when testing this is that if the setting is disabled, the current user’s email address will continue to appear on Segment for the duration of their session. This is related to how Segment handles things on their end. When the setting is disabled, Discourse immediately stops passing user email addresses to Segment.

I haven’t forgotten about the request to pass the `provider_uid` to Segment, but while I was looking at this I was wondering if it would be useful to pass other identifiers to Segment. I was wondering specifically about passing the user’s `name` and `username` to the call to `identify`.

---

<div class="post-metadata">

### Author: ![Cody\_W\_Tucker](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/cody_w_tucker/32/231454_2.png) [@Cody\_W\_Tucker](https://meta.discourse.org/u/Cody_W_Tucker)
#### Post date: [August 19, 2021, 12:42pm UTC](https://meta.discourse.org/t/segment-tracking-theme-component/133335/16 "2021-08-19T12:42:49Z")

</div>

Awesome timing for me @simon thanks.

As far as Name and Username, yes they would also be helpful. A long-term solution would be to implement a way to push everything included at base and also any additional User Fields created in Discourse.

Reasoning, some destinations will require a specific piece of data to work. It would be really helpful to have a UI to build out the payload inside of Discourse. Even if it’s limited to the standard fields in the segment docs [https://segment.com/docs/connections/spec/identify/](https://segment.com/docs/connections/spec/identify/)

---

<div class="post-metadata">

### Author: ![simon](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/simon/32/339122_2.png) [@simon](https://meta.discourse.org/u/simon)
#### Post date: [December 3, 2021, 11:00pm UTC](https://meta.discourse.org/t/segment-tracking-theme-component/133335/17 "2021-12-03T23:00:47Z")

</div>

> [@paigen11](#):
>
> Thanks so much, a `provider_uid` field would be fantastic to have - that should make it possible for us to associate actions by user across our site and Discourse both after they’re sent to Segment.

Sorry for the delayed reply. I’ve looked into this some more. It is not currently possible to set the `provider_uid` through a theme component because Discourse does not send the `provider_uid` to the client. Possibly this is something that could be enabled via a site setting in the future, but for it to work some changes will need to be made to the core Discourse code.

---

<div class="post-metadata">

### Author: ![paigen11](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/paigen11/32/229055_2.png) [@paigen11](https://meta.discourse.org/u/paigen11)
#### Post date: [December 6, 2021, 4:43pm UTC](https://meta.discourse.org/t/segment-tracking-theme-component/133335/18 "2021-12-06T16:43:55Z")

</div>

No problem. Thanks for following up, and for looking into this. Hopefully we can find another way to connect our Discourse users on Discourse and on our site.
