How to set structured data to dynamic pages?

Hi
Is it possible to set built-in data to dynamic pages?
I mean the value of the data will be from the database.
like this example:

import wixSeo from 'wix-seo';
2
3// ...
4
5$w.onReady( () => {
6  wixSeo.setStructuredData(
7    [ 
8      {
9        "@context": "http://schema.org",
10        "@type": "Organization",
11        "name": "My Organization Name",
12        "url": "https://www.myorgdomain.com"
13      },
14      {
15        "@context": "http://schema.org",
16        "@type": "Person",
17        "email": "mailto:john.doe@somedomain.com",
18        "jobTitle": "Professor",
19        "name": "John Doe",
20        "telephone": "(555) 555-555"
21      }
22    ]
23  )
24  .then( () => {
25    console.log("structured data set");
26  } )
27  .catch( () => {
28    console.log("failed setting structured data");
29  } );
30} );

so the data will be:

14      {
15        "@context": "http://schema.org",
16        "@type": "Person",
17        "email": "mailto:john.doe@somedomain.com", // Dynamic Content 
18        "jobTitle": "Professor", // Dynamic Content 
19        "name": "John Doe",// Dynamic Content 
20        "telephone": "(555) 555-555" // Dynamic Content 
21      }

Is it possible?

@yisrael-wix Maybe you can help?

I would suggest reading the article Working with SEO Settings for Dynamic Pages which should clarify SEO for dynamic pages.

If you need further details or clarification, I would recommend contacting Wix Customer Care , as they know best.

Thanks,
but I asked how to set up dynamic data to Json?
any ideas?

You asked, “Is it possible to set built-in data to dynamic pages?
I mean the value of the data will be from the database.”
And, that’s what I attempted to answer.

If you want to “set up dynamic data to Json”:

let structuredData = wixSeo.structuredData;

The above will retrieve the page’s SEO structured data.

Hello @yisrael-wix
I’m interested to have structured data in my Wix data, but i don’t understand the answer… can u make an example please because im not a velo developer.
Do i have to put this expression in the code ? " let structuredData = wixSeo . structuredData ;" And where i put the Json format in the database ?

Thx

Hi,

The problem is that I do not understand how to “connect” the JSON code in a dynamic page (with database) to have the same result as a static page which offers the “advanced SEO” tab to read by Google the structured Data

Here is an example of a Wix template: https://www.wix.com/website-template/view/html/2526

and a short video (1minute) to see what i want:
https://www.screencast.com/t/7d6wzB6tz
1/ i would like to have the same fonctionnality of a static page to insert Json Code
2/As u see, in the data base i can input a JSON code

but now…

who to link ? How to make the JSON code can be read by search engines as structured data in my dynmaic page ?
I don’t see how to use the code: let structuredData = wixSeo.structuredData

Thank you for your help if u can…

I search…
I see 2 things:

and that:

So i understand to insert Aray ? and object ? in the database ?

and the code in the developpement pannel in the dynamic page ?

But i dont kwow how to connect now the JSON code for each line (dynamic page)

@plomteuxquentin or @robert-hamilton or @certified-code some help ?

You just need to grab the data and then assign it to the structure.

import wixSeo from 'wix-seo';

$w.onReady(() => {
 $w('#dynamicDataset').onReady(() => {
 var itemData = $w('#dynamicDataset').getCurrentItem()
//itemData is the item of the database record

 wixSeo.setStructuredData([
        {
		 "@context": "http://schema.org",
 		"@type": "Organization",
                name: itemData.column,
                url: "https://www.myorgdomain.com",
        },
        {
                "@context": "http://schema.org",
                "@type": "Person",
                email: `mailto:${itemData.email}`,
                jobTitle: itemData.title,
                name: itemData.name,
                telephone: itemData.phone,
        },
      ]).then(() => {
         console.log("structured data set");
      })
      .catch(() => {
        console.log("failed setting structured data");
      });
  })
} );


Hello @digital-edge
And Thx.
I tried to do with your code, but I can’t do it.

I took this Wix template: https://www.wix.com/website-template/view/html/2526

  • I integrated the code in the console on the dynamic page
  • then insert for the exemple 2 fields (name and phone) in the database
  • publish data base and website
  • test the url on the Google tool
    it does not detect JSON errors (no code)
    What I have poorly done ?

I made a 60 second video: https://www.screencast.com/t/cSE3ggXg

Thx if u can have a look
Denis

Hello @digital-edge
I tried with this your exemple but with JSON code recognised by Google
BUT… it is not working with dynamic field.

import wixSeo from ‘wix-seo’ ;

$w . onReady (() => {
$w ( ‘#dynamicDataset’ ). onReady (() => {
var itemData = $w ( ‘#dynamicDataset’ ). getCurrentItem ()
//itemData is the item of the database record

wixSeo . setStructuredData ([
{
@context” : “https://schema.org/” ,
@type” : “Recipe” ,
“name” : " itemData.company " ,
“author” : {
@type” : “Person” ,
“name” : “Mary Stone”
},
“datePublished” : “2018-03-10” ,
“description” : “This coffee cake is awesome and perfect for parties.” ,
“prepTime” : “PT20M”
},
]). then (() => {
console . log ( “structured data set” );
})
. catch (() => {
console . log ( “failed setting structured data” );
});
})
} );

Exemple i set in my database the itemdata.company to “123456”
And the Google test failed…

In this example Google should therefore have displayed 123456 but no…

Help please…

Can anyone help with this? Need to add structured data to dynamic pages, populating the schema from fields in the Database

Apparently, this is an interesting topic, but no one is ready to collaborate … :frowning:

My code used to work to achieve this, but just realized it stopped working now. No changes. I can see it’s working in Editor Console, but when viewing the page source code, it returns empty.

<script type="application/ld+json">{}</script>

My code for reference. Any idea for fixes?

File Location: Code Files > Backend > routers.js

The code makes use of afterRouter hook for all /jobs/* URL.
Example URL:

import {ok} from 'wix-router';

export function jobs_afterRouter(request, response) {
	if(response.status === 200 && response.data.items.length === 1) {
		let head = response.head;
		const date = new Date(response.data.items[0]._updatedDate);
		const datePosted = date.toJSON().replace(/T.*/,'');

		head.structuredData = [{
			"@context" : "https://schema.org/",
			"@type" : "JobPosting",
			"title" : response.data.items[0].jobTitle,
			"description" : "<h1>"+ response.data.items[0].jobTitle +"</h1>",
			"datePosted" : datePosted,
			"hiringOrganization" : {
				"@type" : "Organization",
				"name" : "Recruit Hero",
				"sameAs" : "http://www.recruithero.com.my",
				"logo" : "https://static.wixstatic.com/media/f27e6b_11882f1cb12849c9bc7804a56f0570c5~mv2.png"
			},
			"jobLocation": {
				"@type": "Place",
				"address": {
					"@type": "PostalAddress",
					"addressLocality": response.data.items[0].location
				}
			}
		}];

		return ok(response.page, response.data, head);
	}

	return response;
}

Feel free to try. Thanks :grinning:

@shiran-kohai would you be able to assist us on this router issue? The code used to work. Thanks.

I am also looking for a solution to this. Trying to use structured data on a dynamic page using setStructuredData() doesn’t work as expected. (the tag doesn’t appear in the page). However, it does work for static pages.
I am selling tickets to many events on many different dates, and the data is pulled from a dataset. Google needs to know about the data on the event (dynamic) page.

Updates. My code above works again. You can give a try.

After checking, it stopped working previously due to usage of some HTML tag as value. I manage to reduce HTML usage and it works again. Basic tag such as

works. doesn’t work.

Too bad this was not documented.

@yisrael-wix Based on this URL [https://www.recruithero.com.my/jobs/Java-Programmer-Job-Bukit-Jalil-Kuala-Lumpur-Federal-Territory-of-Kuala-Lumpur-Malaysia-14905](https://www.recruithero.com.my/jobs/Java-Programmer-Job-Bukit-Jalil-Kuala-Lumpur-Federal-Territory-of-Kuala-Lumpur-Malaysia-14905

Below)

[T](https://www.recruithero.com.my/jobs/Java-Programmer-Job-Bukit-Jalil-Kuala-Lumpur-Federal-Territory-of-Kuala-Lumpur-Malaysia-14905

Below) his code works. No tag in description property. URL above is using this code.

wixSeo.setStructuredData([
  {
    "@context": "https://schema.org/",
    "@type": "JobPosting",
    "title": "Java Programmer",
    "description": "<h1>Java Programmer</h1><p>Recruit Hero (www.recruithero.com.my) helps talents to connect with best companies and jobs in Malaysia. Recruit Hero's intelligent job matching enables everyone to land better jobs without having to waste time searching & applying for jobs. Visit Recruit Hero (www.recruithero.com.my) to learn more.</p><h2>Java Programmer Job Descriptions</h2><p>Roles:<br /><br />Analyze and designs the system requirementsCapable in creating designs or functional specifications and test plan documents for developmentAdept in developing or implementing new application enhancementsCapable in communicating with the Project Client and Onshore counterparts regarding programming needs and technical deliverablesCollaborate in delivery lifecycle where analysis, design, build, deployment, test, release and supportEnsure all codes produced fulfil the objectives and expected qualityExecute critical tasks necessary for any projectDeliver turnarounds which adhere to the development guidelines and standards of an organizationComplete tasks in a timely manner3rd Party API Integration - Implement 3rd party API to current Backend platformJava development to support backend functions and APIJava web frontend and backend maintenance and support<br />Requirements:<br />Diploma, Bachelor's Degree or Post Graduate Diploma or Professional Degree in Computer Scienceor Software Engineering or equivalent2 years of experience in Java EE application developmentSkillful in the following subjects: Java and SQL programming; any Java EE specification, components or framework;Required Skill(s): Java, JavaScript, HTML, css, MySQL, API, Rest, backend, frontendProficient in developing front-end web programming languages such as HTML, HTML5, Javascript, Wordpress, CSS.Proficient in front-end technologies and integration.Commendable communication skillsProficient in at least English (Mandarin proficiency is a huge added advantage as the company is dealing with HK and China clients)Great team playerMalaysian citizen</p><h2>Java Programmer Skills</h2><p>JavaScript, Mandarin, Java, Java EE, Frontend, Backend, RESTful API, Wordpress</p><h2>Java Programmer Salary</h2><p>Average salary for Java Programmer ranges from RM 4,900 to RM 9,100 per month</p>",
    "datePosted": "2020-10-30",
    "hiringOrganization": {
      "@type": "Organization",
      "name": "Recruit Hero",
      "sameAs": "http://www.recruithero.com.my",
      "logo": "https://static.wixstatic.com/media/f27e6b_11882f1cb12849c9bc7804a56f0570c5~mv2.png"
    },
    "jobLocation": {
      "@type": "Place",
      "address": {
        "@type": "PostalAddress",
        "addressLocality": "Bukit Jalil, Kuala Lumpur, Federal Territory of Kuala Lumpur, Malaysia"
      }
    }
  }
]);

Below code breaks. The only difference is I added

<a href=\"https://www.recruithero.com.my/\">www.recruithero.com.my</a> 

in property description. JSON ID appears invalid as in page HTML.

wixSeo.setStructuredData([
  {
    "@context": "https://schema.org/",
    "@type": "JobPosting",
    "title": "Java Programmer",
    "description": "<h1>Java Programmer</h1><p>Recruit Hero (<a href=\"https://www.recruithero.com.my/\">www.recruithero.com.my</a>) helps talents to connect with best companies and jobs in Malaysia. Recruit Hero's intelligent job matching enables everyone to land better jobs without having to waste time searching & applying for jobs. Visit Recruit Hero (www.recruithero.com.my) to learn more.</p><h2>Java Programmer Job Descriptions</h2><p>Roles:<br /><br />Analyze and designs the system requirementsCapable in creating designs or functional specifications and test plan documents for developmentAdept in developing or implementing new application enhancementsCapable in communicating with the Project Client and Onshore counterparts regarding programming needs and technical deliverablesCollaborate in delivery lifecycle where analysis, design, build, deployment, test, release and supportEnsure all codes produced fulfil the objectives and expected qualityExecute critical tasks necessary for any projectDeliver turnarounds which adhere to the development guidelines and standards of an organizationComplete tasks in a timely manner3rd Party API Integration - Implement 3rd party API to current Backend platformJava development to support backend functions and APIJava web frontend and backend maintenance and support<br />Requirements:<br />Diploma, Bachelor's Degree or Post Graduate Diploma or Professional Degree in Computer Scienceor Software Engineering or equivalent2 years of experience in Java EE application developmentSkillful in the following subjects: Java and SQL programming; any Java EE specification, components or framework;Required Skill(s): Java, JavaScript, HTML, css, MySQL, API, Rest, backend, frontendProficient in developing front-end web programming languages such as HTML, HTML5, Javascript, Wordpress, CSS.Proficient in front-end technologies and integration.Commendable communication skillsProficient in at least English (Mandarin proficiency is a huge added advantage as the company is dealing with HK and China clients)Great team playerMalaysian citizen</p><h2>Java Programmer Skills</h2><p>JavaScript, Mandarin, Java, Java EE, Frontend, Backend, RESTful API, Wordpress</p><h2>Java Programmer Salary</h2><p>Average salary for Java Programmer ranges from RM 4,900 to RM 9,100 per month</p>",
    "datePosted": "2020-10-30",
    "hiringOrganization": {
      "@type": "Organization",
      "name": "Recruit Hero",
      "sameAs": "http://www.recruithero.com.my",
      "logo": "https://static.wixstatic.com/media/f27e6b_11882f1cb12849c9bc7804a56f0570c5~mv2.png"
    },
    "jobLocation": {
      "@type": "Place",
      "address": {
        "@type": "PostalAddress",
        "addressLocality": "Bukit Jalil, Kuala Lumpur, Federal Territory of Kuala Lumpur, Malaysia"
      }
    }
  }
]);