One of my clients is currently testing with Gmail Annotations in their email template. They want to be able to add/remove the Gmail annotation from their email template in a simple manner. They make use of template-based emails, so if I hardcode the annotation code in the head tag in the template it will always be in there.

What I thought I would do is to create some Content Blocks, referencing Ampscript, so that the client could drag a block of Ampscript in their template which would display the Annotation code or hide it. I've done this using the following example:

<!-- This part is part of the email template -->
         var @showGmailAnnotation
         if @showGmailAnnotation == "showGmailAnnotation" then  


    %%[ else ]%%

    %%[ endif ]%%

The contentblock that's being referenced contains the following:

   var @showGmailAnnotation
   SET @showGmailAnnotation = "showGmailAnnotation"

When I ran a test email I did not get any syntax issues. I did however notice that the IF is not being executed, instead it executes the ELSE statement. In hindsight this makes sense, because the var declared above the IF statement does not have the SET value yet.

When I put %%=ContentBlockbyName("gmailAnnotationCode")=%% in the else block it executed in the following output:


         <table cellpadding="0" cellspacing="0" width="100%" style="min-width: 100%; " class="stylingblock-content-wrapper"><tr><td class="stylingblock-content-wrapper camarker-inner">    

    <!-- Gmail Annotations code: START -->
    <div itemscope="" itemtype="http://schema.org/Organization"> 
      <meta itemprop="name" content="Gmail">
      <meta itemprop="logo" content="">
    <div itemscope="" itemtype="http://schema.org/DiscountOffer"> 
      <meta itemprop="description" content="">
      <meta itemprop="discountCode" content="">
      <meta itemprop="availabilityStarts" content="">
      <meta itemprop="availabilityEnds" content="">
    <div itemscope="" itemtype="http://schema.org/PromotionCard"> 
      <meta itemprop="image" content=""> 
    <!-- Gmail Annotations code: END --></td></tr></table>

    <!-- AMPSCRIPT END -->

I have removed the content from the output, but I was very surprised to see that Marketing cloud wraps the Ampscript output in a table. It seems that the annotation is not working for this reason.

Is there anyone that has an idea how to resolve this issue?

  • Are your AmpScript Blocks you receive via contentblockbyname codesnippets or other types. If they are not of the codesnippet type you should change them to codesnippets and try if that changes the output. – Johannes Schapdick Apr 5 at 11:21
  • Why are you initializing @showGmailAnnotation twice? – Adam Spriggs Apr 5 at 11:40
  • @ Johannes I have tried to change the referenceblock to a code snippet but did not get a different result. – PatrickSF Apr 5 at 12:09
  • 1
    Also as a note, most renderers will move all non-meta / styling code (e.g. DIV tags) down into the body automatically or just delete it (high likelihood of causing issues). So that could also be part of your issue. In Schema.org, it is not supposed to go inside the head tag, but under the body tag anyway. Not sure why you are trying to insert this inside the head tag. – Gortonington Apr 5 at 12:58
  • 1
    I've resolved the issue with a workaround. @Gortonington was correct and I was able to make a content block that my client is able to drag in to their template if they wish to use the Gmail annotation. This seems like the best solution for now, the only thing I do not like about it is that it's invisible in the visual editor in content builder. Thanks for the help everyone! – PatrickSF May 7 at 7:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.