Hello everyone!
I am happy that you've once again joined me with my Umbraco blog posts. I hope everyone had a great week and is ready to start another one! If you are not yet up to speed on what I am doing with this series, then here is a quick summary.
I am creating an SEO package within Umbraco. The SEO package will have many different functionalities like:
- Sitemaps
- Robots.txt
- Meta tags and hopefully much more! Currently, I am working towards a first version and I've been sharing my progress with these weekly blog posts. So, let's get started!
Script Manager
Today I'll talk about a new feature for the SEO package! I know that this is yet another feature and that the Meta Tags feature isn't finished yet. But don't worry, it'll be finished soon!
So about the script manager feature. This was something that was suggested by a colleague of mine. We always have to add a Google Tag Manager script to each website and sometimes even a custom script. Instead of having to add this by a developer, it would be better to do this within the CMS! And so we have the script manager:
I didn't want this to just be a simple textbox somewhere that you could fill in. I thought it would be even better to have different script definitions that allow you to render multiple different scripts on your website. For example, if I now select the option "Custom Script", I'll see the following:
This way you can also add custom scripts to your website without any development. Currently, I have the following definitions programmed:
- Google Tag Manager
- Google Analytics
- Custom Script
Each definition has the ability to add a script in the body or the head. For example, the Google Tag Manager definition needs to add a script to the head and to the body. But the current system allows for doing that. Let us also take a look at the code for such a definition!
I do have to admit that the render function is a bit of a mess right now. Ideally, I would like to move this to a razor view for rendering, but I haven't gotten there yet. I'll also still need to add some caching and some cleanup of the code. But the logic is there already. Let's quickly go through the definition in a bit more detail.
We have the alias for internal use. The name is shown on the interface for the user. Then we have the fields, which are of type ConfigurationField. These are Umbraco fields and I also saw them used in Contentment, so I also wanted to use them here. I might even start using them in the meta tag package.
Improvements
So what do I still want to improve before this feature is all done? For the first release, I will still improve a bit of the code, add some caching and take a look at the rendering. Maybe also add some different script definitions. After that, I am sure it is good enough for most use cases.
I also like this feature a lot because it is a small feature, but also something that is very nice to have included. Which reminds me, I also wrote a blog item about "How small changes can make a world of difference". I think it is quite fitting for this feature.
And that is all for this week. Next week I'll probably be working on both meta tags and the script manager. So until next week!