1

I am appending dynamic structured data to the head of html as and when my ajax response comes. Something like:-

function appendSchemaToScript(schema){
    var el = document.createElement('script');
    el.type = 'application/ld+json';
    el.text = JSON.stringify(schema);
    document.querySelector('head').appendChild(el);
  }

This script tag is showing perfectly when i inspect elements. However when I choose GoogleBot as user agent, the script tag is not getting appended at all. I deployed these new changes yesterday. Do I have to wait for some time to see the changes picked up?

If not, why is google bot not displaying my dynamically appended script? Is it because it is after initial page load? If yes, how should I add dynamically rendered structured data?

| improve this question | | | | |
  • How are you testing as Googlebot? The fact it is not being added when you do that test should be a clue to why the real Googlebot can't see it. – Tony McCreath Jan 23 at 21:28
  • Check out the following article - this explains what happens when search bots are served pages with AJAX or other JavaScript-dependent functionality. A long but useful read that may give you some ideas: onely.com/blog/ultimate-guide-javascript-seo – Henry Visotski Jan 23 at 23:43
  • @TonyMcCreath Hi .. Thanks for your reply. I am testing it as a google bot by selecting GoogleBot as a user agent from network conditions. The script tag is being added(inspected from elements) if the user agent is automatically selected but not when i manually select the user agent to be google bot. Should I wait for search console to recache my page? – Anisha Jan 24 at 5:19
  • @HenryVisotski Thank you .. it is a very informative article. However.. I still don't fully comprehend what steps I should follow to add dynamic JSON-LD schema to head after initial page load. – Anisha Jan 24 at 6:02
  • 1
    @TonyMcCreath Turns out, I was able to resolve the issue by waiting for a few days. Search console does not pick JSON-LD structured data even during live url test.However, now after reindexing, the new structured data is getting picked up perfectly. Thank you for your help – Anisha Jan 27 at 9:57

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.