Amazon link rewriting for affiliate codes

As far as I know there is no way in Discourse to handle rewriting Amazon links, which leads to me double-checking to make sure people aren’t trying to pull a fast one when they do post an Amazon link.

This could happen in one of two ways (or both):

  • Add code to strip all affiliate codes from any Amazon URL
  • Add code to replace and/or add affiliate codes into any Amazon URL.

I know this happened over at StackExchange a long time ago, so I’m guessing it’s probably fairly easy to do.

I’m not personally that worried about adding the affiliate codes, but it would be nice to make sure that other people aren’t adding them to their links, and I’m guessing it would be a really good feature for forum owners that want to make money from links on their forum.

15 Likes

Yes please.

4 Likes

I created a script to do exactly this, it’s here: GitHub - deanbarrow/Affililink: A free way to automate your affiliate scheme. http://affililink.com/

It’ll add your affiliate tag to any Amazon link, and also rewrite other peoples with tags with your own.
It works on the client side so it’s just a case of adding a javascript file to your head section and configuring it.

It will do the same for eBay and can be setup to work with any affiliate scheme which uses a http://domain.com/?CODE=XYZ style linking structure.

I’ll be happy to answer any questions to help you get set up.

2 Likes

Have you tested it in Discourse? Does it work on a Discourse forum?

2 Likes

I don’t see why not but unfortunately I don’t have a forum running at the
moment. If it doesn’t by default I will be able to patch it.

Is anyone willing to help? Please get in touch.

1 Like

This should be fairly simple in a plugin. @codinghorror do you think this is a core feature or plugin thing?

2 Likes

Any news about the plugin?

1 Like

I second the love for this plugin.

2 Likes

If someone could give me access to a working installation I could put a plugin together.
I don’t currently have the resources to setup discourse.

1 Like

How much access do you need? I’m willing to help if I can. My forum is at http://forum.strats.co.

1 Like

I’m not sure entirely however I’ve just had a look at the setup instructions and it seems a lot easier compared to when I last looked. I’ll fire up a VM when I get a chance and see what I can do. Thanks for your offer and I’ll get back to you if need be.

1 Like

Just a thought, it would be interesting to make such a script as configurable as possible. There are a lot of affiliate strings out there and it would be interesting to rewrite other links within the same package.

Specifically, I run a gaming forum and there are common links used, some without affiliate codes as well. I’d like to be able to tack on a code to these links to help fund the forum maintenance.

1 Like

The script as it stands allows you to add any affiliate code as long as it works in the foo.com/?tag=bar type format. There is also another option to allow you to overwrite existing codes or not.

The plugin will just give a pretty GUI to manage it. Shouldn’t be too tricky to create, leave it with me :wink:

3 Likes

Did someone start to work on it?
I’m still interested.

3 Likes

I started working on a solution. Can some one help me to finish it?
https://meta.discourse.org/t/how-to-rewrite-some-urls-in-posts-amazon-affiliate/17385/12?u=camilleroux

1 Like

Personally I think that Discourse should automatically strip out any affiliate codes from Amazon URLs when the post is saved. No reason to recalculate that every single time, and better to have nice clean data in the database.

Adding the codes should probably happen separately, on display, and could be separate.

1 Like

I’d suggest a plugin…otherwise you’ll end up either integrating other affiliate link processing into the core engine, which becomes unwieldy…or all other affiliate link processing will be configured in plugins and the amazon in another config area…making things confusing.

It’s a good idea. Could you tell me how to do that?

It might help to look at the cooked_post_processor.rb to see what Discourse does to posts. As part of the post processing after making a post, the plugin would look at the text, strip away any existing affiliate tags and add in your chosen tags (which could be defined as an environment variable in the app.yml?). Thus the text is permanently changed, which would be the cleanest solution.

https://github.com/discourse/discourse/blob/master/lib/cooked_post_processor.rb

I’ve got a local version of Discourse running now so I’m going to start looking at this.

2 Likes