Ebay EPN: Source map error

The Ebay affiliate program provides a script that converts links on the clientside. It’s a simple two-line thing:

<script>window._epn = {campaign: [XXX_ID_XXX], smartPopover:false};</script>
<script src="https://epnt.ebay.com/static/epn-smart-tools.js"></script>

I realize I can’t simply add these two lines for security reasons. There’s a bit of a discussion here EPN Smart Links

I have created a very simple theme component and placed the code in the common/head_tag.html file:

The id is specified on the component page and the console logs the correct id. However, it does not appear to update any URLs.

I have added this epn-smart-tools.js as a content security policy exception. In the brower console I get this warning though:

It looks like this “from-url.js.map” referenced in the epn-smart-tools.js is the problem. I wrote a simple html file on my desktop and ran it locally and there doesn’t seem to be an issue - leading me to believe it’s more likely a issue on the discourse end than from my browser.

What these source maps do and how discourse interacts with them are outside the limits of my knowledge. Any advice here? Am I overlooking something?

Source maps are optional files that help debugging minified assets. Since you don’t control this asset, and doesn’t have any control over it’s source you should ignore this warning.


Thanks for the info @Falco and happy birthday.

I figured out the problem was where I added that <script src="… line.

This worked for me:

<script type="text/discourse-plugin" version="0.8">

  window._epn = {campaign: settings.epn_id, smartPopover:false};

  var script = document.createElement('script');
  script.src = 'https://epnt.ebay.com/static/epn-smart-tools.js';
  var head = document.getElementsByTagName("head")[0];


The next problem I ran into is that elements that are dynamically loaded are do not have the script applied to them. For instance, if I refresh the page on a topic, the posts that load will have the affiliate link but scrolling to reveal more posts - those ones don’t.

Is there a way to run the script every time a new element is loaded?

1 Like

Ideally you would do that on the server side, once a new post is saved. We have a plugin that exactly this for Amazon so you should be able to adapt it for eBay: GitHub - discourse/discourse-affiliate

If you still want to do it on the client side, you can follow this helpful tutorial: Link rewriting for affiliate codes - #8 by Johani