Has anyone had any success using a SEO script on an sp_page?

ChrisB15000
Tera Contributor

Hello all!

 

I'm curious to know whether anyone here has successfully managed to use an SEO script on an sp_page to add custom tags to a portal page, and if so, you'd be willing to share your experience?

 

Background / Use Case:

The organisation I'm working for, is utilising the ServiceNow for Microsoft 365 integration, which supports link unfurling in MS Teams.

Out of the box, the adaptive cards displayed in Teams are pretty basic, and don't show any dynamic content from the page allegedly being previewed.

I have since learned that the adaptive cards can be modified using Open Graph tags.

For example, inserting the following tag into the page header would result in the page title in the card being set to "Hello".

<meta property="og:title" content="Hello">

Through some further reading, I discovered that I could configure ServiceNow to render these custom tags on portal pages using an SEO script associated with the page - specifically by overriding the generateCustomTagsForSEO() method.

 

Initially, I am trying to prove the concept by getting basic tags to render on my ec_home page, using the following script include:

 

var SPSEOHeaderTags = Class.create();
SPSEOHeaderTags.prototype = Object.extendsObject(SPSEOHeaderTagsSNC, {
    initialize: function() { },

	generateCustomTagsForSEO: function() {
        // return custom tags as array of strings that will be updated in the page dom as-is
        // ['<meta custom-tag=""  property="og:title" content="Service Portal">']
		gs.info("This is running!!");
		return ['<meta custom-tag=""  property="og:title" content="Custom Title">',
				'<meta custom-tag=""  property="og:description" content="Custom Description">'];
    },

    type: 'SPSEOHeaderTags'
});

However, no matter what I do, those custom tags are not appearing in my page source.

My gs.info statement is also not showing up in the system logs, which leads me to believe that the script is not even being executed.

There is zero documentation from ServiceNow around when and how the SEO script is invoked during the page rendering process, so I am hoping to connect with somebody who has been through a similar struggle!

 

Thanks,

2 REPLIES 2

ethantaylor555
Mega Contributor

Hey Chris 

Really good question — and you’re not alone here! The SEO script on sp_page (using generateCustomTagsForSEO()) can be a bit tricky because it doesn’t always trigger unless the SEO Script field is explicitly set on that page record and the portal page cache is cleared afterward.

A few quick checks that might help:

  • Make sure your SPSEOHeaderTags Script Include is Client Callable = false and Accessible from = All application scopes.

  • In the sp_page record (e.g., ec_home), set the SEO Script field to your script include name.

  • Clear Service Portal caches (/cache.do) and re-test — sometimes tags don’t show due to cached page templates.

  • If you’re testing in a non-public page, make sure it’s indexable (no login required); otherwise, the SEO script won’t execute.

If it still doesn’t fire, try logging from the SPSEOHeaderTagsSNC parent class to ensure it’s extending correctly — a small naming mismatch can silently break the override.

Let us know what happens after trying those steps — I’ve gotten OG tags to render using this method before, so it’s definitely doable.

 
 
 

ethantaylor555
Mega Contributor

Yes, it’s possible, but make sure your SEO Script is linked to the sp_page, clear the portal cache, and ensure the page is public/indexable. Also, confirm your Script Include is accessible from all scopes. Those are the main reasons it usually doesn’t fire.