# Understanding how embedding works on remote site

**URL:** https://meta.discourse.org/t/understanding-how-embedding-works-on-remote-site/27781
**Category:** Support
**Created:** [4월 20, 2015, 10:22오후 UTC](https://meta.discourse.org/t/understanding-how-embedding-works-on-remote-site/27781 "2015-04-20T22:22:48Z")
**Posts on this page:** 13
**Page:** 1

<div class="post-metadata">

### Author: ![rhulse](https://avatars.discourse-cdn.com/v4/letter/r/91b2a8/32.png) [@rhulse](https://meta.discourse.org/u/rhulse)
#### Post date: [4월 20, 2015, 10:22오후 UTC](https://meta.discourse.org/t/understanding-how-embedding-works-on-remote-site/27781/1 "2015-04-20T22:22:48Z")

</div>

I am setting up embedding of a Discourse forum and I am having trouble understanding how to make it work.

I’m not able to create topics by RSS at this stage so I need to do the creation manually.

My question is how does Discourse tie a topic to the page on the remote site?

(For my use case it would be simpler to put the required topic URL to embed in the JS snippet rather than ‘self’. Is that likely to be possible?)

---

<div class="post-metadata">

### Author: ![tobiaseigen](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/tobiaseigen/32/539204_2.png) [@tobiaseigen](https://meta.discourse.org/u/tobiaseigen)
#### Post date: [4월 20, 2015, 10:36오후 UTC](https://meta.discourse.org/t/understanding-how-embedding-works-on-remote-site/27781/2 "2015-04-20T22:36:14Z")

</div>

here’s the page you want to look at:

> [@Embed Discourse comments on another website via Javascript](https://meta.discourse.org/t/embedding-discourse-comments-via-javascript/31963):
>
> Discourse has the ability to embed the comments from a topic in a remote site using a Javascript API that creates an IFRAME. For an example of this in action, check out [Coding Horror’s blog](http://blog.codinghorror.com/welcome-to-the-internet-of-compromised-things/#discourse-comments). The blog is run via [Ghost](https://ghost.org/) but the comments are embedded from his [Discourse forum](http://discourse.codinghorror.com/t/welcome-to-the-internet-of-compromised-things/3550). One important thing to note with this setup is that users have to navigate to your forum to post replies. This is intentional, as we feel that the posting interface on a Discourse forum is currently much richer than what we …

---

<div class="post-metadata">

### Author: ![rhulse](https://avatars.discourse-cdn.com/v4/letter/r/91b2a8/32.png) [@rhulse](https://meta.discourse.org/u/rhulse)
#### Post date: [4월 22, 2015, 6:01오후 UTC](https://meta.discourse.org/t/understanding-how-embedding-works-on-remote-site/27781/4 "2015-04-22T18:01:24Z")

</div>

OK, I have reread that post and it says this

> If your site does not have an XML feed, Discourse will create topics based on your page contents using a readability algorithm. It’s remarkably accurate for those cases when your site doesn’t have a feed.

I cannot see how this works from the post end of things. How do you tell a post what page it should be using?

The other issue I have is that the URLs change as stories are updated. It would seem to me that this will break the integration if I rely on the current URL; it may not be the same as the created URL.

@eviltrout - are you able to comment on this?

---

<div class="post-metadata">

### Author: ![eviltrout](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/eviltrout/32/5275_2.png) [@eviltrout](https://meta.discourse.org/u/eviltrout)
#### Post date: [4월 24, 2015, 8:11오후 UTC](https://meta.discourse.org/t/understanding-how-embedding-works-on-remote-site/27781/5 "2015-04-24T20:11:18Z")

</div>

The code you embed tells discourse there’s a new post to embed. For example on [eviltrout.com](http://eviltrout.com):

```javascript
var discourseUrl = "http://fishtank.eviltrout.com/",
    discourseEmbedUrl = "http://eviltrout.com/2014/12/22/watch-ember-tv.html";
(function() {
  var d = document.createElement('script'); d.type = 'text/javascript'; d.async = true;
  d.src = discourseUrl + 'javascripts/embed.js';
  (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(d);
})();

```

The first time that script is executed it contacts discourse and says "give me the contents for `discourseEmbedUrl`. Discourse will then say, hey, there are no comments, but in the background enqueue a job to crawl that page for its contents. So shortly afterwards, it will be crawled and run through readability.

The key is `discourseEmbedUrl`.

Your site will indeed break if `discourseEmbedUrl` changes. However, I assume the original URL still works even when it’s updated? If you leave `discourseEmbedUrl` as the original value it will not import the article twice and the comments will continue to work.

---

<div class="post-metadata">

### Author: ![rhulse](https://avatars.discourse-cdn.com/v4/letter/r/91b2a8/32.png) [@rhulse](https://meta.discourse.org/u/rhulse)
#### Post date: [4월 26, 2015, 2:17오전 UTC](https://meta.discourse.org/t/understanding-how-embedding-works-on-remote-site/27781/6 "2015-04-26T02:17:53Z")

</div>

Ah right, the penny has dropped now.

Also, I did not have a _embed by username_ set, so I presume the system could not create the post.

I can easily control the URL used - I have a field in the database called initial\_url which is the url that existed when the item was created (this is for Google Analytics).

One thing I’d be interested in your thoughts around is embedding the same topic in more than one story.

A good example of this use-case is [this radio programme series](http://www.radionz.co.nz/national/programmes/thiswayup/collections/sourdough). It is on sourdough and ran over many weeks. We might embed the forum in the first story, and then embed it in the second (and so on) so people can enter the discussion on any of the pages at any time.

It would be quite cool if there was a mode ‘non-create or update mode’ where you can embed any topic on any page. This is something we’d use a fair amount as it allows you to seed a new story on the same topic with the existing discussion and avoids having many separate topics about essentially the same conversation.

I am also going to add an RSS feed of stories we want topics for to our CMS so I can be explicit about the content that appears in the first post.

RSS + arbitrary embed appear to do the golden path for us, but I’d be interested on hearing if there are other ways to do this.

---

<div class="post-metadata">

### Author: ![cklepeis](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/cklepeis/32/116281_2.png) [@cklepeis](https://meta.discourse.org/u/cklepeis)
#### Post date: [6월 12, 2015, 3:01오후 UTC](https://meta.discourse.org/t/understanding-how-embedding-works-on-remote-site/27781/7 "2015-06-12T15:01:32Z")

</div>

I’d be interested in the details of the “readability algorithm”. It looks like the title being pulled for the topic is from the meta title field - in our case its better to pull from the h1 tag. Also, not sure how its pulling the content for the topic… as of now its not pulling the correct details we want in there. For example, we have a description on our page, and then have a bunch of other stuff that shouldn’t be in the Discourse descripton… its pulling all of the other stuff and omitting description.

I also noticed that its not possible to change the title and content of the topic after its auto created - I receive a generic error message.

---

<div class="post-metadata">

### Author: ![codinghorror](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/codinghorror/32/110067_2.png) [@codinghorror](https://meta.discourse.org/u/codinghorror)
#### Post date: [6월 12, 2015, 9:41오후 UTC](https://meta.discourse.org/t/understanding-how-embedding-works-on-remote-site/27781/8 "2015-06-12T21:41:24Z")

</div>

> [@cklepeis](#):
>
> I’d be interested in the details of the “readability algorithm”

> <https://stackoverflow.com/questions/3652657/what-algorithm-does-readability-use-for-extracting-text-from-urls>

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [6월 12, 2015, 9:44오후 UTC](https://meta.discourse.org/t/understanding-how-embedding-works-on-remote-site/27781/9 "2015-06-12T21:44:39Z")

</div>

It’s a bit of a hacked up ruby gem, not 100% the same as that

---

<div class="post-metadata">

### Author: ![cklepeis](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/cklepeis/32/116281_2.png) [@cklepeis](https://meta.discourse.org/u/cklepeis)
#### Post date: [6월 13, 2015, 2:52오전 UTC](https://meta.discourse.org/t/understanding-how-embedding-works-on-remote-site/27781/10 "2015-06-13T02:52:33Z")

</div>

Does it have any logic to apply weights to an H1 tag so that it would win out and become the topic title (like a specific ID or class)? From the original Readability code here [http://arc90labs-readability.googlecode.com/svn/trunk/js/readability.js](http://arc90labs-readability.googlecode.com/svn/trunk/js/readability.js) I saw that if the meta title is \< 10 or \> 150 characters the h1 tag would be used. Right now our meta title is just “Home” so that must be something that was customized.

Here’s our specific use case. We’re planning on launching a new website in a couple days. It’s a daily deal website, and the new deal is shown on the homepage similar to [meh.com](http://meh.com). Changing the meta title every day on the homepage isn’t something we necessarily want to do. We definitely want to foster community so embedding the discourse topic posts for each deal is ideal.

With the JS code on our site to map the page to the forum topic, I’m just appending a query string that would be distinct to the deal of the day.

A suggestion for a future Discourse update would be to allow us to enter a selector in the admin (when not using an xml / atom feed) to find the title and description for the topic creation.

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [6월 13, 2015, 6:52오전 UTC](https://meta.discourse.org/t/understanding-how-embedding-works-on-remote-site/27781/11 "2015-06-13T06:52:06Z")

</div>

We have settings for selectors I even made commits to the gem to support that

> **[Commits · cantino/ruby-readability](https://github.com/cantino/ruby-readability/commits)**
>
> Port of arc90's readability project to Ruby. Contribute to cantino/ruby-readability development by creating an account on GitHub.

---

<div class="post-metadata">

### Author: ![cklepeis](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/cklepeis/32/116281_2.png) [@cklepeis](https://meta.discourse.org/u/cklepeis)
#### Post date: [6월 14, 2015, 3:34오전 UTC](https://meta.discourse.org/t/understanding-how-embedding-works-on-remote-site/27781/12 "2015-06-14T03:34:28Z")

</div>

Thanks, I missed that. I applied the blacklist selector to the title element, just as a test to see if I could get it to pull the H1 as the title. Didn’t work - didn’t event create the topic (not surprised… I wouldn’t normally add a class to a title).

My workaround for the title is this:

```
discourseEmbedUrl = 'http://[my site].com/?eid=[event ID]&ref=cpdiscourse&title=[url encoded event title]';

```

Then if ref and title are present in the querystring, I change the meta title just for Discourse… adding a noindex so this variation doesn’t get picked up by search engines.

The blacklist selector worked perfectly for allowing me to prevent certain things from showing up in the description.

---

<div class="post-metadata">

### Author: ![system](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/system/32/443519_2.png) [@system](https://meta.discourse.org/u/system)
#### Post date: [10월 14, 2018, 7:28오전 UTC](https://meta.discourse.org/t/understanding-how-embedding-works-on-remote-site/27781/13 "2018-10-14T07:28:55Z")

</div>



---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [10월 14, 2018, 10:56오후 UTC](https://meta.discourse.org/t/understanding-how-embedding-works-on-remote-site/27781/14 "2018-10-14T22:56:09Z")

</div>


