Roll out web analytics at scale pt. 4 – Distributing your Google Tag Manager containers

You

Background

We’re back for the fourth part of our five part series. This article will give you the tools you need to easily distribute the Google Tag Manager containers you create using Google Apps Script to your customers. If you haven’t read parts one, two and three, you can check them out by following the links.

Introducing the MailApp service

Google Apps Script includes built-in email libraries to allow you to send emails. These can be used alongside HTML to send fully branded emails, but this blog will just cover the basics.

So let’s go back and revisit how we made a container, using our configuration object and the TagManager service.

 

var params = {
     	    'gtmAccountId': '1234567',
            'customerName': 'Billy Bob',
            'analyticsAccountId': '1242535',
            'websiteUrl': 'https://billybob.co.nz',
            'callTrackingId': '1234567', //optional
            'analyticsPropertyId': 'UA-123456', //optional
            'customerEmail': 'billy@bob.com' //added this
}

 var path = 'accounts/' + params.gtmAccountId;

var container = call(function() {
         return TagManager.Accounts.Containers.create({
                    'name': params.customerName,
                    'usageContext': ['WEB']
                },
                path)
        });

        var containerPath = container.path;

        var containerId = container.accountId; 

I’ve also added a customer email address to our params object so we have somewhere to send the containers . To send the emails you can use the MailApp service or GmailApp service. Using GmailApp will provide better deliverability, as it is using your actual Gmail account to send the emails. You may need to use MailApp if you do not have a custom domain on your gmail account. The syntax for the sendEmail() method is the same for both.

GmailApp.sendEmail(paramsHardcoded.customerEmail, 'Some subject', 'Some body'); 

This example would send an email to billy@bob.com , with the subject ‘Some subject’ and the body of ‘Some body’.

Applying this to our containers

We can now send our previously created Google Tag Manager container to our customers using this service. You’re going to need to escape the html in the container snippet – but luckily I’ve already done this for you.

We’re also going to need to use the htmlBody option within the sendEmail() method so the snippet appears nicely in the email.

I’ve added this as a txt snippet because to avoid issues with nested code elements.

Download it here.

This should come through looking like this:

Seeing as it’s using HTML, you can customise your email template to look however you want. It’s totally up to you.

Final thoughts

I would recommend adding a bit more content to your emails explaining the purpose of Google Tag Manager, particularly if this is going to clients without any knowledge of it.

I’ve found agencies generally prefer to use something like Marketo to send their containers – but this is a great option for those who don’t have access to that sort of software.

Our final part in the series will cover some strategies for checking the installation status of your containers – as this whole process is pointless unless the containers are implemented. Until next time, have fun!

Comments

There are no comments on this entry.