Having said this, I am not quite sure whether this is feasible, or a good approach at all. Curious to learn from your experience generating structured data!
This is the right direction. I suspect that it’s going to be a lot of manual work, and I’m trying to imagine how to do it in a more automated way.
I can think of a couple of different ways to make it more automated. The one I would suggest trying first is to move the custom code into a Formula field in Airtable, and then pull the text of that script out of window.records and append it to the page.
Ah, I see what you mean: essentially generating the json in a single field in Airtable and pulling this in to. the page, rather than each field individually.
Haven’t tried generating/storing JSON in Airtable, and it doesn’t feel like the cleanest approach either, but agree that it could be much more efficient.
What about Google Tag Manager? Could it possibly use the data that’s on the page already, rather than pulling in window.records values?
I don’t know Google Tag Manager at all, but just off the top of my head, I’m thinking that’s the opposite direction of information flow from what you want. You’re trying to generate markup from your database that is intended for Google’s crawler to ingest, whereas GTM is about Google and others injecting stuff into your page from the outside.
If you’re not crazy about generating the JSON in an Airtable formula, here are two more approaches.
You could write some custom code that runs when the page loads, and assembles the JSON with JavaScript string operations, substituting data in from window.records, then injecting it into the page DOM.
I think creating a JSON via formula in Airtable then using a small script to get from the record and create a script tag with that JSON might be the best approach. It might feel scrappy but I think it’s the best option and those customisations always require some hacking
Much appreciate the help and suggestions. Let me go ahead creating the JSON in Airtable and adding this in a simple script as custom code to include it in the detail pages.
Made a few attempts to insert the structured data stored from an Airtable field (SEO:JSON-LD) into the of the page. While the console.log displays the structured data correctly, it does not actually appear within the .
The line document.head.appendChild(jsonldScript); seems to be failing. Thoughts anyone?
Interesting, thanks for trying. Double-checked that the Airtable field doesn’t already include the tags, and also tried with that exact schema.org definition, but without any luck.
I copied and pasted your code, so I don’t think I have anything to offer there!
Maybe it’s actually working for you? How are you going about confirming whether it’s working? What I did was to inspect the DOM of the page in the Google Chrome developer tools, and this is what I found, near the bottom of the page:
Ah, you got me - it is working as expected indeed! I had been looking for the code in the Page Source, rather than Elements within the Dev Tools. Mystery solved - much appreciate the help!
There’s (at least) one more hurdle to get over. I would not assume that the Google crawler can be counted on to wait until this JavaScript runs to add the JSON to the page, before it starts processing. I think this needs to be tested.
If you find that Google isn’t properly waiting and isn’t finding the JSON, then that’s really going to push the ball back to Softr to solve this problem, as I don’t see any way for custom code to get access to the data any sooner.
For what it’s worth, I didn’t have to do anything fancy with quotation marks. I used a field of type Long Text and did not turn on rich text formatting.
Yep, should work well without quotation marks as long as you can use a regular text field. In my case I will only generate the JSON within Airtable itself, and therefore need to use a Formula field for the values to be dynamic.