Detecting keywords in another Asset's metadata field


(James Porich) #1

Matrix Version: 5.3.4.0

Hi guys, not sure if this has been covered elsewhere.

The scenario:

For my pages since we have some busy editors and they don’t always have time to enhance their pages - I opted to make a page’s <meta name="description"> a metadata field which an editor can overwrite (if they have time/feel it’s necessary), but the default is a keyword targetting the asset contents so there’s at least some sort of relevant description in Google:

%globals_asset_contents^striphtml^trim^replace:\s+: ^maxchars:153^append: | (site name)%

Basically the idea being since they’re mostly online editors, they will be creating a relevant opening paragraph which would make for some sort of relevant Google Description. while skipping any default descriptions that might pull in irrelevant words (these are sort of not-quite “long tail” pages generally so need some tailoring Google-wise).

The Challenge:

In another area of the site, we’re listing out “card” style previews of these pages, with a thumbnail, title, link to the page etc… But also we are going to have a short intro text about the page that it’s linking to.

So what better intro description than the same one that you’d use for a Google description!

That was the plan anyway - pull that default text, if they wanted to make it bespoke, they can manually change this via metadata.

The problem:

Can’t use javascript (due to some restriction by the organisation)

I can get that metadata field to pull all good, however it pulls the text, then evaluates, and we end up with the Google description/evaluated keywords of the “showcase” page, rather than of the page it is showcasing.

What I’d like to know:

When building an Asset List is there some way of evaluating whether a metadata field contains keywords?

I was intending to use the logic “if the description metadata field of the asset it is currently processing contains keywords (i.e. default value), pull specifically %asset_id% contents and sanitize them (rather than the general %global_metadata_description% default which evaluates as the showcase page’s description) - if it doesn’t contain keywords however, we can assume this is some custom description written in and pull that value”.

I hope that makes sense. Happy to clarify further - cheers.

(p.s. bit of an ancillary functionality, not really too important - but figured if there is a technique it would definitely be handy down the line too while solving this problem)


(Bart Banda) #3

Are you just wanting to print the description metadata of each listed page and if empty, print the first 153 characters of that asset’s contents?

Would something like this do:

%begin_asset_metadata_description%
  %asset_metadata_description%
%else_asset%
  %globals_asset_contents^striphtml^trim^replace:\s+: ^maxchars:153^append: \| (site name)%
%end_asset

You would then just need to make your default value of the description metadata field empty.

Just an FYI, Google won’t necessarily use your meta description tag as the description in search results, only if it can’t find any better content on the page in the context of the search query.


(James Porich) #4

Hi Bart -

Yup - that is correct.

Just in the unfortunate situation where that particular field has a default value (no keyword detection for %asset_metadata_x^default:%?)

I guess I can change the Design to try %begin_asset_metadata_description^eq:%%first 153 cahracters%

Also as far as Google’s preferences for descriptions - yeah, one of those weird things where Google is constantly improving in it’s identification of content, so starting to get to a point of begin moot - but still unfortunately not quite there from what we’ve seen :frowning:

Thanks for the input :slight_smile:


(Bart Banda) #5

Unfortunately not, but what’s the default value? Wouldn’t it be best to be empty? That way, you can just check if empty, print the asset contents shortened, if not, print the meta value.


(James Porich) #6

Hi Bart,

Currently the default metadata value is:

%globals_asset_contents^striphtml^trim^replace:\s+: ^maxchars:153^append: \| (site name)%

If I were to delete this, what would be the best way of implementing:

%begin_asset_metadata_description%
  %asset_metadata_description%
%else_asset%
  %globals_asset_contents^striphtml^trim^replace:\s+: ^maxchars:153^append: \| (site name)%
%end_asset%

In the head of the document? Would it need to be inserted directly in to the Design as a Design Customisation? (I’m not too familiar with Designs at this stage!)


(Bart Banda) #7

Yep, that’s it. The best way to actually add it in is to print it all in a standard page and then nest that into a design customisation into the head.

Checkout the site and system templates from the community site which should hopefully give you an idea of the best practices around this sort of things in designs: https://matrix.squiz.net/resources/templates/content-templates


(James Porich) #8

Awesome, cheers dude :slight_smile: