Getting up and running with Java API for Google Tag Manager

This tutorial will get you started with using the java google tag manager api, using a google api service account which is added as a user in google tag manager admin.

Please note that you CANNOT push events to Google Tag Manager using the API (like dataLayer.push({}) in JavaScript)! See (This was my goal, but because I struggled with getting things set up, I’m creating this tutorial for people that want to use the API to do other things.)

Step 1 – Create service account

Go to, log in, and create a new service account with key type JSON:

The resulting file should look like this:

Step 2 – Grant access to the services account

Go to, log in, go to admin > user management > new.

The email should be identical to the value for the “client_email” key in the file you downloaded in step 1 (accountname@trans-airfoil-1…

Step 3 – List containers using Java Google API

If you’re using maven, include the package:

If you’re not using maven, see here.

The following code will do a very simple thing, simply list all available container ids attached to the given account id.

What next?

Have a look at API Explorer for ideas on what to do next.

Leave a Reply

Your email address will not be published. Required fields are marked *