Troubleshooting

My custom code doesn't run

Scripts from Custom code in Project settings run on every page of your Ghost site, and only there. They never run on the Fantasma canvas, so you test them on the site itself. To open Custom code, click the sliders icon in the icon rail, Project settings, then Custom code. Clicking a script's name opens its page with Where, Runs and the code.

Check the basics first

  • Publish the theme, or download it and upload it in Ghost, after you add or change a script. See Publish your theme to Ghost or Download your theme and upload it in Ghost.
  • To see whether the script reached a page, open the page in your browser, right-click it, select View Page Source or the like, and search for a word from your script, such as your ID G-ABC123DEF4 or the service's name.
  • Test on your live site in a private window, with ad blockers and privacy extensions turned off. Such extensions block analytics for some of your real visitors too.
  • Analytics services can take several minutes to show a visit. Check the service's live or real-time view.

The script is turned off

In the list of scripts, each script has a switch at the end of its row. A script that is off is left out of the theme. Turn it on, then publish again.

The script has an error

A script with an error shows "Has errors" in red in the list, and the theme ships without it. Click the script to see the error under the code, such as "A <script> tag is not closed." Fix it, then publish again. If you pasted the code from a service, copy its whole snippet again, because a missing last line often causes this. If the error still makes no sense, contact us with it.

A script whose Runs is After analytics consent or After marketing consent runs only after a visitor allows that kind of cookie in your cookie banner. Analytics services belong to analytics consent, and ad and tracking pixels to marketing consent.

  • Without a banner, the script page says "This project has no cookie banner, so this script will never run." Click Add a banner in that note, or set Runs to Always. If your site uses a cookie banner from another service, set Runs to Always and let that service hold the script back, as its instructions say.
  • "The Default layout has a cookie banner, but no template uses it." means visitors never see the banner. In the Templates list at the top of the left sidebar, select each template and set Layout to Default in the right sidebar.
  • With a banner, accept cookies on your site, then reload the page. If you declined before, open a private window to see the banner again. Add a cookie banner explains the banner.

A script that waits never counts the visitors who decline. Your numbers in the service are lower for that reason.

Only <script> tags can wait. An <img>, <iframe> or <noscript> part of the code loads at once, and a line under the code asks you to remove that part. The <script> part still does the job for visitors who allow it.

The code still has a sample ID

A ready script, one you picked by name under Add script, such as Google Analytics, starts with a sample ID. Until you replace it, a line under the code says, for example, "Replace G-XXXXXXXXXX with your own value." Paste your own ID from the service, then publish again.

The code is in the wrong place

Some services need their code at the start of the page. Read where the service's install instructions put the code, and pick the same in Where, such as Head for most analytics, or Body start for some tag managers. Add analytics and other scripts explains each place.

The same script runs twice

If the same code is also in Ghost Admin's Code injection, it loads twice and the service counts each visit twice, or one copy breaks the other. Keep it in one place. Either place works for a script that runs always. Use Custom code when the script must wait for consent. Code injection runs on every theme and never waits for the cookie banner.

Contact support

If none of these fix it, contact us and send:

  • the address of a page on your site where the script should run
  • a screenshot of the script's page in Custom code

Was this article helpful?