Specify Double Quotes for Thymeleaf's inline Javascript - thymeleaf

I'm trying to add some Schema Markup to a site built with Thymeleaf. My first thought was to use the ld+json method:
<script type="application/ld+json" th:inline="javascript">
{
"#context": "http://schema.org",
"#type": "LocalBusiness",
"address": {
"#type": "PostalAddress",
"streetAddress": /*[[ ${C:Location.street}]]*/,
"addressLocality": /*[[ ${C:Location.city}]]*/,
"addressRegion": /*[[ ${C:Location.state}]]*/,
"postalCode": /*[[ ${C:Location.zipcode}]]*/
},
}
</script>
But Thymeleaf outputs those strings in single quotes, which apparently doesn't validate as correct JSON when checking with https://developers.google.com/structured-data/testing-tool/
Is it possible to tell Thymeleaf to use double quotes here? I can do the HTML microdata markup if all else fails but I'd prefer not to since it's not as pretty and modular.

I tried to use text mode:
<script type="application/ld+json" th:inline="text">
{
"#context": "http://schema.org",
"#type": "EmailMessage",
"potentialAction": {
"#type": "ViewAction",
"url": "[[ #{${url}} ]]",
"name": "[[ #{message.button.text} ]]"
}
}
</script>
Output:
<script type=3D"application/ld+json" xml:space=3D"preserve">
{
"#context": "http://schema.org",
"#type": "EmailMessage",
"potentialAction": {
"#type": "ViewAction",
"url": "https://watch-movies.com/watch",
"name": "Watch movie"
}
}
</script>

This might be helpful for people using html.erb
<script type="application/ld+json">
{
"#context": "http://schema.org",
"#type": "EmailMessage",
"potentialAction": {
"#type": "ViewAction",
"url": <%= resource.photos.first(3).map(&:url) %>,
"name": "some text"
}
}
</script>
Here instead of having something like ["url1", "url2", "url3"] for the url field you will get [&quote;url1&quote;, &quote;url2&quote; &quote;url3&quote;].
To get the desired result use .to_json.html_safe
<script type="application/ld+json">
{
"#context": "http://schema.org",
"#type": "EmailMessage",
"potentialAction": {
"#type": "ViewAction",
"url": <%= resource.photos.first(3).map(&:url).to_json.html_safe %>,
"name": "some text"
}
}
</script>

Related

Test Schema in my own gmail id

<script type="application/ld+json">
{
"#context": "http://schema.org",
"#type": "EmailMessage",
"potentialAction": {
"#type": "ConfirmAction",
"name": "Approve Expense",
"handler": {
"#type": "HttpActionHandler",
"url": "https://myexpenses.com/approve?expenseId=abc123"
}
},
"description": "Approval request for John's $10.13 expense for office supplies"
}
</script>
This is a sample schema I copied from the example. I am using gmail html client in chrome to send HTML emails using this tag.
Why doesn't the action show up? I am sending it to my own email and I received the email. But no actions are shown.

Events within email to update calendar

I am new to this and I am trying to provide a service to my tennis players where they can go on website, fill up a form for reserving the court. The form will send an email with time and place when they want to play. Upon confirmation, that should update the calendar. I tried various scenarios provided, but it did not work. I am not sure what am I missing. I just send en email to myself as follows:
<html>
<body>
<script type="application/ld+json">
{
"#context": "http://schema.org",
"#type": "EventReservation",
"reservationNumber": "IO12345",
"underName": {
"#type": "Person",
"name": "John Smith"
},
"reservationFor": {
"#type": "Event",
"name": "Google I/O 2013",
"startDate": "2017-08-30T08:30:00-08:00",
"location": {
"#type": "Place",
"name": "Moscone Center",
"address": {
"#type": "PostalAddress",
"streetAddress": "800 Howard St.",
"addressLocality": "San Francisco",
"addressRegion": "CA",
"postalCode": "94103",
"addressCountry": "US"
}
}
}
}
</script>
<p>
Dear John, thanks for booking your Google I/O ticket with us.
</p>
<p>
BOOKING DETAILS<br/>
Reservation number: IO12345<br/>
Order for: John Smith<br/>
Event: Google I/O 2013<br/>
Start time: May 15th 2013 8:00am PST<br/>
Venue: Moscone Center, 800 Howard St., San Francisco, CA 94103<br/>
</p>
</body>
</html>
but I see it just a text as above.
thanks in advance,
Hagop
You are missing a property : reservationStatus that is required. I've used the Basic event reminder without a ticket JSON-LD:
<html>
<head>
<script type="application/ld+json">
{
"#context": "http://schema.org",
"#type": "EventReservation",
"reservationNumber": "E123456789",
"reservationStatus": "http://schema.org/Confirmed",
"underName": {
"#type": "Person",
"name": "John Smith"
},
"reservationFor": {
"#type": "Event",
"name": "Foo Fighters Concert",
"startDate": "2017-09-06T11:30:00-12:30",
"location": {
"#type": "Place",
"name": "AT&T Park",
"address": {
"#type": "PostalAddress",
"streetAddress": "24 Willie Mays Plaza",
"addressLocality": "San Francisco",
"addressRegion": "CA",
"postalCode": "94107",
"addressCountry": "US"
}
}
}
}
</script>
</head>
<body>
<p>
An event was reserved.
</p>
</body>
</html>
Here is the result:
I've tried your code and added the reservationStatus and it worked. You can test your schemas using Email Markup Tester.
Hope this helps.

Order schema not showing right on Gmail

I'm trying to implement the Order schema as presented on : https://developers.google.com/gmail/markup/reference/order
<script type="application/ld+json">
{
"#context": "http://schema.org",
"#type": "Order",
"merchant": {
"#type": "Organization",
"name": "Test Ltd."
},
"orderNumber": "56d59b633427b",
"orderStatus": "http://schema.org/PaymentComplete",
"acceptedOffer": {
"#type": "Offer",
"itemOffered": {
"#type": "Product",
"name": "Test Products"
},
"price": "41.09",
"priceCurrency": "USD",
"eligibleQuantity": {
"#type": "QuantitativeValue",
"value": "1"
},
"url": "http://project1.local/account/tickets",
"potentialAction": {
"#type": "ViewAction",
"target": "http://project1.local/account/tickets"
}
}}
</script>
The issue is that the email shows like a normal email. What am I doing wrong?
Thank you!
PS: The code validates on https://developers.google.com/structured-data/testing-tool/
Try using the JSON I've posted below. PaymentComplete is not recognized, so I used OrderDelivered. You can find more info here:
https://schema.org/OrderStatus
I noticed the word "tickets" in your URL, are you intending to use the order schema for ticket confirmations? I would suggest using event reservation instead. Using this will integrate with Google Now cards and also input the event into the user's Calendar. You can still generate a action button by using url or modifyReservationurl.
<script type="application/ld+json">
{
"#context": "http://schema.org",
"#type": "Order",
"merchant": {
"#type": "Organization",
"name": "Test Ltd."
},
"orderNumber": "56d59b633427b",
"orderStatus": "http://schema.org/OrderDelivered",
"priceCurrency": "USD",
"price": "41.00",
"acceptedOffer": {
"#type": "Offer",
"itemOffered": {
"#type": "Product",
"name": "Test Products"
},
"price": "41.00",
"priceCurrency": "USD",
"eligibleQuantity": {
"#type": "QuantitativeValue",
"value": "1"
}
},
"url": "https://project1.local/account/tickets",
"potentialAction": {
"#type": "ViewAction",
"target": "https://project1.local/account/tickets"
}
}
</script>

Multiple email markups for Gmail and Inbox

Does Google support adding multiple markups in one email? For e.g i want to add an action button markup for Gmail and a Highlight markup for Inbox. Can this be done? I did not find any documentation for it.
Yes, having multiple markups is supported. For example, for a flight reservation.
All the code until "arrivalTime" is standard for a basic flight confirmation, but with the addition of "checkinUrl" you add a Go-To action to create a [Check In] button in Gmail.
<script type="application/ld+json">
{
"#context": "http://schema.org",
"#type": "FlightReservation",
"reservationNumber": "RXJ34P",
"reservationStatus": "http://schema.org/Confirmed",
"underName": {
"#type": "Person",
"name": "Eva Green"
},
"reservationFor": {
"#type": "Flight",
"flightNumber": "110",
"airline": {
"#type": "Airline",
"name": "United",
"iataCode": "UA"
},
"departureAirport": {
"#type": "Airport",
"name": "San Francisco Airport",
"iataCode": "SFO"
},
"departureTime": "2017-03-04T20:15:00-08:00",
"arrivalAirport": {
"#type": "Airport",
"name": "John F. Kennedy International Airport",
"iataCode": "JFK"
},
"arrivalTime": "2017-03-05T06:30:00-05:00"
},
"checkinUrl": "http://united.com/onlinecheckin.html",
"potentialAction": {
"#type": "CheckInAction",
"target": "http://united.com/onlinecheckin.html"
}
}
</script>

Testing EmailMessage json in gmail

I also do not see the button in my test emails to myself. It is in a gmail account. Does the script tag have to come directly after the body tag? The email tester https://www.google.com/webmasters/markup-tester/ says the emails good and pulls out the script tag fine.
<script type="application/ld+json">
{
"#context": "http://schema.org",
"#type": "EmailMessage",
"description": "Answer",
"action": {
"#type": "ViewAction",
"url": "testuri",
"name": "Survey"
},
"publisher": {
"#type": "Organization",
"name": "Orgname",
"url": "https://www.Orgurl",
"url/googlePlus": "https://plus.google.com/+Orgname/posts"
}
}
</script>
For testing does it matter if it is a via?
"#gmail.com via amazonses.com"
I have the correct security stuff setup per the suggested testing. I see
mailed-by: amazonses.com and
signed-by: amazonses.com

Resources