Wednesday 17 June 2020

Monitoring and fixing 404 errors with Google Analytics

For website with dedicated 404 Page eg. /404/

How to build the report for 404 errors from internal links yourself

  • Go to Customization > Custom Reports in Google Analytics and click on +New Custom Report.
  • Select the report type Flat table.
  • Select the dimensions Page, Previous Page Path and Page Title.
  • Select the metric Unique Pageviews.
  • Add a filter that excludes the value (entrance) for the dimension Previous Page Path. This filter makes sure that only 404 errors that were preceded by a page view on your own website (and thus caused by an internal link) show in the report.
  • Add a Regex filter for the page title that contains the expression that helps you identify your 404 error page (“404” in the example below, but it could also be “page not found” or something else, depending on the title tag of your 404 error page).

How to build the report for 404 errors from external links yourself

  • Go to Customization > Custom Reports in Google Analytics and click on +New Custom Report.
  • Select the report type Flat table.
  • Select the dimensions Page, Full Referrer and Page Title.
  • Select the metric Unique Pageviews.
  • Add a filter that includes the value (entrance) for the dimension Previous Page Path. This filter makes sure that only 404 errors that were not preceded by a page view on your own website (and instead caused by an external link) show in the report.
  • Add a Regex filter for the page title that contains the expression that helps you identify your 404 error page (“404” in the example below, but it could also be “page not found” or something else, depending on the title tag of your 404 error page).

For website with current page as 404 Page 

How to build the report for 404 errors from internal links yourself

  • Go to Customization > Custom Reports in Google Analytics and click on +New Custom Report.
  • Select the report type Flat table.
  • Select the dimensions Page, Previous Page Path and Page Title.
  • Select the metric Unique Pageviews.
  • Add a filter that includes the value "Page Title of 404 page" for the dimension Page Title. 

How to build the report for 404 errors from external links yourself

  • Go to Customization > Custom Reports in Google Analytics and click on +New Custom Report.
  • Select the report type Flat table.
  • Select the dimensions Page, Full Referrer and Page Title.
  • Select the metric Unique Pageviews.
  • Add a filter that includes the value "Page Title of 404 page" for the dimension Page Title. 

Monday 25 May 2020

The data layer

Google Tag Manager functions best when deployed alongside a data layer. A data layer is a JavaScript object that is used to pass information from your website to your Tag Manager container. You can then use that information to populate variables and activate triggers in your tag configurations.

Rather than referencing variables, transaction information, page categories, and other important signals scattered throughout your page, Tag Manager is designed to easily reference information that you include in your data layer source code. Implementation of a data layer with variables and associated values, ensures that they will be available as soon as you need them to fire tags.

When you set up your website or mobile app to work with Tag Manager and a data layer, think about what categories of information the data layer should handle, such as:

  • Product data: Product name, price, category
  • Marketing campaign information: Traffic source, medium
  • Transaction data: Cart value, checkout date
  • Customer information: New or returning customer

Create a data layer variable

Data layer variables enable Tag Manager to read values from your data layer implementation and pass those values to tags, triggers, and other variables. A data layer object is made up of a list of key/value pairs. A key is a category of things – a book's category, title, or author. Each key could have different values. A book's title key could have a value of 'Ulysses', 'War in Peace', 'A Brief History of Time', etc.

Add data layer code to your web page

To set up your data layer, work with a developer to add the following snippet of code to the <head> section of your web page above your container snippet:

<script>
  dataLayer = [];
</script>

Add information to the data layer with the dataLayer.push() command:

<a href="#" onclick="dataLayer.push({
    'bookCategory': 'fiction',
    'bookTitle': 'Cien años de soledad',
    'bookAuthor': 'Gabriel García Márquez'
});">Book details</a>

Set up the data layer variable

Once you have the key that you would like to work with, you can proceed to create a data layer variable:
  • Click Variables.
  • Under User-Defined Variables, click New.
  • Click Variable Configuration and select Data Layer Variable as the variable type.
  • In the Data Layer Variable Name field, enter the key exactly as it was written in the code (e.g. bookTitle, not book title.)
  • In most cases you should leave the Data Layer Version set to the default value of Version 2. Learn more.
  • Save the variable.
  • Repeat these steps for every data layer key that you would like to have available as a variable in Tag Manager.
  • Publish the container.