lemoynelibrary / lemoyne

Files used in setting up new web design in LibGuides v2 and elsewhere
5 stars 1 forks source link

Add Library Hours Schema to Google Search Results #29

Open tomkeays opened 6 years ago

tomkeays commented 6 years ago

Google has a Schema specification for hours of business. https://developers.google.com/search/docs/data-types/local-business

LibCal can generate Schema data in JSON-LD format that Google is able to parse. https://blog.springshare.com/2016/03/08/libcal-2-4-update-now-live/

The following code generated by the LibCal widget needs to be added to the footer element of library pages.

<script> 
window.jsonldcb585 = function(data) { 
   var e = document.createElement("script"); 
   e.type = "application/ld+json"; 
   e.text = JSON.stringify(data); 
   document.body.appendChild(e); 
}; 
var jsonld_585 = document.createElement("script"); 
jsonld_585.setAttribute("src","https://api3.libcal.com/api_hours_grid.php?format=jsonld&iid=567&lid=585&callback=jsonldcb585"); 
document.body.appendChild(jsonld_585); 
</script> 
tomkeays commented 6 years ago

Generated LibCal JSON-LD data includes "Card Entry" hours data in addition to the main "Library Hours" data (snippet appended below). We have entered "Card Entry" as a "department" under the main "Library Hours" entry in LibCal to display when you need to swipe your keycard for entry to the building. The worry here is that Google is not going to know what to do with it. The LibCal widget to generate the <script> code is all or none and has a select option for the "library" but not the "department".

I had hoped that there might be a parameter that could be manually added to the API call URL to suppress the department hour data but, according to SpringShare support, there's no way to remove it.

https://api3.libcal.com/api_hours_grid.php?format=jsonld&iid=567&lid=585&callback=jsonldcb585

However, Greg Sigountos at SpringShare said, "I did run this output through Google's structured data checker, and didn't find any issues there, so Google might be able to interpret this correctly for you."

We're going to try it to see what Google does with it in practice.

jsonldcb585({
  "@context": "http:\/\/schema.org",
  "@type": "LocalBusiness",
  "name": "Library Hours:",
  "geo": {
    "@type": "GeoCoordinates",
    "latitude": "43.048366",
    "longitude": "-76.090515"
  },
  "openingHoursSpecification": [{
    "@type": "OpeningHoursSpecification",
    "validFrom": "2018-04-02",
    "validThrough": "2018-04-03",
    "opens": "08:00",
    "closes": "02:00"
  }, {
   .
   .
   .
  }, {
    "@type": "OpeningHoursSpecification",
    "validFrom": "2018-05-27",
    "validThrough": "2018-05-27",
    "opens": "13:00",
    "closes": "17:00"
  }],
  "department": [{
    "@type": "LocalBusiness",
    "name": "Card Entry:",
    "openingHoursSpecification": [{
      "@type": "OpeningHoursSpecification",
      "validFrom": "2018-04-02",
      "validThrough": "2018-04-03",
      "opens": "21:00",
      "closes": "02:00"
    }, {
     .
     .
     .
    }, {
      "@type": "OpeningHoursSpecification",
      "validFrom": "2018-05-24",
      "validThrough": "2018-05-24",
      "opens": "18:00",
      "closes": "22:00"
    }]
  }]
});
tomkeays commented 6 years ago

I'm only going to add this code to resources.library.lemoyne.edu and lemoyne.libcal.com and see if Google can parse it. My thinking is that the hours are relevant to these domains so these are the only places the code needs to be added.

Test search: https://www.google.com/search?num=30&newwindow=1&q=falcone+library+hours

tomkeays commented 6 years ago

Looking at this Schema example -- http://schema.org/Library -- I'm wondering if the Schema data could be changed by SpringShare.

Perhaps also include address and url? Currently, the LibCal Hours module has no place to specify address details or url and it's not in the general settings either.

"address":  {
    "@id": "_:school_edu_library_1",
    "@type": "PostalAddress",
    "contactType": "Mailing address",
    "streetAddress": "Le Moyne College",
    "streetAddress": "1419 Salt Springs Road",
    "addressLocality": "Syracuse",
    "addressRegion": "NY",
    "postalCode": "13214",
    "addressCountry": "United States"
  },
"url": "http://resources.library.lemoyne.edu/library"