We are developing a cloudpage using new content builder functionality with multiple HTML blocks (4-5 html blocks ) so my question is in which block we should keep our Google tag manager Java script code so we can track/see analytics of the entire cloud page and not that particular html block?

  • You can add your tracking code via Code View: i.imgur.com/CKe52CN.png Sep 8, 2021 at 11:48
  • @StijnHoste Thank you for your response and answer
    – Jay
    Sep 12, 2021 at 6:43

1 Answer 1


A couple things:

  1. You should add the tracking code via Code View as @StijnHoste said in the comment.
  2. Any Javascript inside of any content blocks will be removed once you reopen it.
  3. If you were to put the tracking inside a block, it would run for the whole page.

Code View
You are able to fully edit every aspect of your webpage 'template' inside of this view to allow you to change styles, scripts, meta tags, etc. This will display each content block placeholder as <div data-type="slot" data-key="xxxx"> though and will not display the actual content that is in the block here. This is where you would add your analytics tracking or any similar scripting.

Javascript in Content Block
As you can see in the official docs, JS is not allowed inside of content blocks. The way they say to handle it is to use 'code only' blocks (HTML or Code Snippet) and do not complete the script tags inside one block. Something like:

Block 1:

  ... my JS ...

Block 2:


I personally prefer a different method to host JS. See this post for the full answer. Basically you would either store your full JS script (including script tags) inside a DE field and then output inside a TreatAsContent or you would concat the script tags together via AMPscript so that the parser does not recognize the tags and does not strip them.

Lookup to DE:

SET @jscript = Lookup('yourFormDE', 'Javascript', 'Form', 'Form 1')


Concatting script blocks:

set @scriptBeg = Concat('<','script','>')
set @scriptEnd = Concat('</','script','>')

your javascript code here

Block affects all of page
This is just to note that the page blocks are compiled together into a single source prior to being sent from server to the client. This means that there is absolutely no difference between a page that uses blocks compared to a page that is raw HTML as seen by the client. Just wanted to make a note on this here as it seemed you were of the impression this was not true.

  • Thank you @Gortonington for answer and explanation !!
    – Jay
    Sep 12, 2021 at 6:42

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .