Library › Coding AI › Marketing and content

Build tagged campaign links with one sheet formula

Practice: Asking for a format you can use. About 5 minutes.

About this exercise

Write a Google Sheets formula for E2 (filled down to E500) that builds the tracking link from A2 (page URL), B2 (source), C2 (medium) and D2 (campaign) as utm_source, utm_medium, utm_campaign in that order. Rows with an empty A must stay blank. Where a URL already contains a ?, join the tags with & instead. The campaign must come out lowercase with spaces turned into hyphens, because analytics splits Spring Sale and spring-sale. One formula in one code block, then under 20 words outside the code.

Common mistakes when you ask AI for this

  • Forgetting the empty rows. The AI's formula fills hundreds of blank rows with half-built links. Try: Add: "If A2 is empty, return blank."
  • Not mentioning existing ?. The AI always adds ?utm_source=, which breaks links that already have a question mark. Try: Add: "If A2 already has a ?, join with & instead."
  • Not setting the case rule. The AI copies the campaign as typed, so capitals and spaces split your analytics. Try: Add: "Campaign lowercase, spaces turned into hyphens."
  • Getting a menu of options. The AI likes to offer two or three versions of the formula, so you're left to pick and test them yourself. Try: Add: "Give one formula only, in one code block, no alternatives."
  • Getting a tutorial. By default the AI explains every part of the code at length, which you then have to scroll past. Try: Add: "After the code, one line under 12 words. Nothing else."

What a strong prompt includes

  • Keeps empty rows blank
  • Handles URLs with a ?
  • Sets the campaign format
  • Asks for one answer only
  • Limits the explanation

Practice this now ↑

Related exercises