← All posts

How to Give Each Instagram Commenter a Unique Discount Code

To give each commenter a unique discount code on Instagram, you need three things: a list of single use codes, a record that ties each code to one person, and a rule that reserves the code before the DM is sent. The sending is the easy part. Duplicates come from retries and timing, and you prevent them in your own records, not on Instagram.

Why one code per person matters

A shared code like WELCOME10 is simple, but it leaks. It gets posted in deal groups and used by people who never saw your post, and you cannot tell which redemptions came from the campaign.

Unique codes fix that. Each code works once, so your discount budget has a ceiling. You can see who redeemed.

How to give each commenter a unique discount code on Instagram

  1. Generate the codes in your store. Most ecommerce platforms can create a batch of single use codes and export them as a file. Create more than you expect to need.
  2. Load them into a list with a status. Each row needs the code, a status (free, reserved, sent) and room for the person it went to.
  3. When a keyword comment arrives, look up the person first. If they already have a code, stop. Do not assign another.
  4. Reserve a code before sending. Mark one free code as reserved for this person, in a single step that cannot be interrupted halfway.
  5. Send the DM with that code. You get one private reply per comment, so the code goes in the first message.
  6. Record the outcome. Sent, or failed with the reason. The reservation stays with the person either way.

The order of steps 3 to 5 is the whole trick. Reserve first, send second. If you send first and record afterward, any crash between the two leaves a code in someone's inbox that your list still thinks is free. For the campaign setup around this, see how to send an automatic DM when someone comments on Instagram.

Why duplicates happen

The same person comments more than once. They write the keyword, see nothing within ten seconds, and write it again. Each comment is a separate event. If your logic is "every keyword comment gets a code", this person gets two.

Retries after a timeout. Your tool sends the DM and the response is slow. The tool assumes failure and tries again. The first attempt had in fact gone through. Now the person has two messages, and possibly two different codes.

API lag. We ran into this in our own campaign: the comments API does not immediately return the replies the tool itself posted seconds earlier. If your tool decides whether a comment is handled by checking "is there already a reply from us under it?", it will sometimes see no reply, conclude the comment is new, and handle it again.

Keep the state in your own records

All three causes have the same cure. Instagram is not your database. The source of truth for "has this comment been handled" and "does this person have a code" must live in records you control.

At minimum, keep:

Record Key What it prevents
Handled comments Comment ID Processing the same comment twice
People Instagram user ID Giving one person two codes
Codes The code itself Giving one code to two people

Then apply these rules:

  • Use the user ID, not the username. People change usernames. IDs stay the same.
  • Make the comment ID unique in your records. If a second attempt tries to insert the same comment, the insert fails and the work stops there.
  • Assign codes atomically. "Find a free code and mark it reserved" must be one operation, so two runs cannot grab the same row.
  • On a retry, reuse the reservation. If the person already has a reserved code, the retry sends that same code.

When someone says they did not get it

Some DMs land in the Requests folder and some are never delivered. The person will comment "I didn't get mine". The wrong response is to assign a fresh code, because people learn that complaining earns an extra discount.

The right response is to send the same code again. Invite the person to DM you, and when they do, look them up and reply with the code already reserved for them. The full flow is in why an Instagram DM goes to Requests.

What to do when codes run out

Decide this before launch, because it will happen at the worst moment, when the post is doing well.

  • Stop cleanly. When no free code is left, the campaign should pause itself. It must never send a DM with an empty code field or the literal text of a placeholder.
  • Have a refill ready. Keep a second batch generated in your store so you can upload it in a minute.
  • Tell people. A fixed public reply such as "This round of codes is gone, follow us for the next one" is better than silence.
  • Mind the 7 days. A private reply can only be sent within 7 days of the comment. If you refill a week later, the people who commented during the gap are out of reach by DM.

The short version

Reserve before you send, key everything on IDs, and treat your own records as the only truth. That is the logic we built into CometoDM after our own campaign: one code per person, the same code again on a retry, and an automatic stop when the list is empty. It is in development with a waitlist, and the rules above hold whether you use a tool or a script of your own.