The Most Important Factors to Consider with Laravel SEO

An important factor to consider with your technical SEO is the information you supply to search engines in the head of your pages, this includes the title tag, meta data such as description and OpenGraph data.

Another factor to consider is the performance of your application, when working with Laravel, one of it's best and also worst features is that we are free to create the design pattern of our application as we see fit. Unoptimised database queries, bloated front-end assets and long-running tasks that should be handled by the queue are some of the most common reasons for slow Laravel applications. Installing packages like the Laravel Debugbar can assist you in identifying these issues.

The quality of your HTML is also a factor, using semantic tags to clearly identify portions of your content is a must. You should make use of HTML5 semantic tags such as section, article, nav, aside, header and footer.

SEO Generator Service Class Example

Having a solid design pattern in place for generating each page or posts unique SEO head tags is absolutely crucial to getting the results you are striving for with your SEO strategy. By making use of the SEO Tools package mentioned previously, we can easily create a service class which will handle the SEO generation by using values from the database, let's take a look.

<?php

namespace App\Services;

use App\Models\Post;
use Artesaos\SEOTools\Facades\OpenGraph;
use Artesaos\SEOTools\Facades\SEOTools;

class PostSEOService
{
    public function generate(Post $post): void
    {
        SEOTools::setTitle($post->title);
        SEOTools::setDescription($post->meta_description);
        OpenGraph::addImage($post->twitter_image_url);
    }
}
<?php

namespace App\Http\Controllers;

use App\Models\Post;
use App\Services\PostSEOService;

class PostController extends Controller
{
    public function show(Post $post, PostSEOService $seo)
    {       
        $seo->generate($post);

        return view('posts.show', compact('post'));
    }
}

Validate Your Application

Using tools like Ahrefs to perform a site audit should be part of your overall testing strategy to ensure that your application is optimized for search engines. Site audit services like Ahrefs can raise issues such as meta description length, broken links, orphaned content and more.

SEO validation with ahrefs

Using the data you can generate from services such as Google's PageSpeed insights and SEO auditing applications you can ensure you're application is ready to be crawled.

Use a Sitemap

Sitemaps are often overlooked when considering SEO and in truth, lots of small websites don't require one. Sitemaps allow us as developers to make a list of pages and tell search engines that these are the pages we'd like crawled. A properly linked website will allow search engines to find all of the pages and posts our application has so a sitemap wouldn't actually improve our SEO.

However, including a sitemap doesn't negatively impact your SEO so why not? There a plenty of reasons to include the functionality to produce a sitemap early on as once you grow, the need for a sitemap may occur and then you would be scrambling to implement the functionality.

For Laravel, I Spatie's Laravel Sitemap package will handle the generation of the sitemap itself, then we just need to decide when to generate the sitemap. Usually when performing CRUD operations on posts is a good place to start.

Once you have a sitemap generated, it is a good idea to link your sitemap in Google's Search Console.

Use a sitemap with Laravel

Implement Web Analytics

Tracking which portions of your application receive the most traffic will help you understand your audience. Having tracking data to work from, you can identify the portions of your website that you could consider improving.

Are your users landing on a certain page and just leaving? Is there a particular post that has lots of traffic? These are all very important questions that you should know.

Using a web analytics service can guide you towards figuring out the answers to these question but you still be diligent enough to analyse this data further in your own business context.

Track traffic with Google Analytics

Think SEO From The Start

SEO shouldn't be a last thought when developing any web application. Building in SEO features from the very start will eliminate a lot of stress in the future.

From implementing keywords into your hardcoded content to database design, every feature of your application should have it's possible impact on SEO considered.

Copyright © 2024 | bonnick.dev