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.

Publishing, versions, and approvals

Publish containers

When you publish a container, Tag Manager will make your changes active for the environment specified. If you've added or edited tags, triggers, and variables in a workspace, you will need to publish those changes to make those changes operational on your website or mobile app.

To publish your current workspace:

  • Click Submit at the top right hand side of the screen. The Submit Changes screen will appear, with options to publish the container and save a version of your container.
  • Select Publish and Create Version if it is not already selected.
  • Review the Workspace Changes section to see if your configuration appears as you expect.
  • Enter a Version Name and Version Description.
  • If you have Tag Manager configured to use multiple environments, use the Publish to Environment section to select which environment you'd like to publish to.
  • Click Publish.

Versions

A version is a snapshot of a container configuration at a particular time. You can save the current state of a workspace as a version at any time. This enables you to revert your workspace back to a previous version if necessary.

Versions can make it easier to recover from mistakes. For example: If someone accidentally publishes a container version before it's ready for production, you can revert your workspace to an earlier version and publish it.

Users with Approve access or higher can create versions. Every time a container is published, a version of that container is recorded.

To save the current workspace as a version before it is published:
  • Click Submit. The Submit Changes screen will appear, with options to publish or save a version. (Google Marketing Platform customers will see an additional option to Request Approval.)
  • Click Create Version.
  • Enter a Version Name and Version Description.
  • Click Create.
To publish a previously saved version of a container to the site:
  • Click Versions.
  • Click the desired version in the table.
  • Click Action and then Publish.
Tag Manager maintains a publish history, so you can see when versions were live and who published them. To see the publish history, go to Versions and look for entries with a date in the Published column.

To replace the current container version with a previously saved version:
  • Click Versions.
  • Click the Actions menu next to the desired container version.
  • Select Set as Latest Version.
This replaces the current container draft with the content of the selected container version. You may then make any additional modifications to the container draft, and publish your changes when ready.

To publish a specific version from the Versions screen: Identify the version you'd like to publish and then select Publish To... from the Actions menu.

When you publish or create a version, enter a Version Name and Description that will make it easy to know what changes are being made. For example:
  • Version name: "GA page view tag - initial launch"
  • Description: "Launch the Google Analytics pageview tag on example.com.

Approvals

This feature is only available in Google Tag Manager 360, which is included in the Google Marketing Platform.

Containers owned by Tag Manager 360 accounts can add approvals to their workflow. Users with Edit access or higher will see an additional option to request approval to publish changes that they have made.

Request approval

To request approval for changes made to a workspace:
  • Click Submit.
  • Select Request Approval.
  • Optional: Click Choose Approver to identify someone to review and approve your request.
  • Optional: Use the Comment section to add a descriptive comment to help an approver understand the requested changes.
  • Click Request.
If you are using a workspace that has a pending approval, you will see a banner that indicates the workspace is pending approval status. Click View Request to see the changes as they were requested.

Approve requests

The Approvals page will list all approval requests that have been submitted for a given container. These items will include requests to publish workspaces, approve External Account Links, and add tags pushed from Campaign Manager. When there are requests pending approval, the Approvals tab will have an indicator next to it:
  • A blue circle means there are open requests that are either assigned to another user, or are available for anyone to review and approve.
  • A red circle means there are open requests assigned specifically for you to review.
To review and approve or reject an approval request:
  • Click the Approvals tab.
  • Click the name of the entry to be approved.
  • Review the details of the request.
  • Optional: To assign a specific approver, click Choose Approver.
  • Optional: To add comments to a request, click Add Comment.
  • Click Approve to approve the request, Send Back to deny the request and have the original submitter make further edits, or Withdraw to cancel a request.