DecisionRules & Google Tag Manager

How to integrate DecisionRules with Google Tag Manager?

This page is connected to Google Tag Manager, which calls DecisionRules upon every page initialization. We have made a simple demo rule that returns the response that you can see below.


    

   

To set up a custom integration of DecisionRules with Google Tag Manager, follow the steps below.

Basic Setup

Open your Google Tag Manager project. Create a new Custom HTML Tag, call it dr-call and copy paste the following code to it. Do not forget to enter your existing DecisionRules rule ID, Solver API key and input data.

You may of course edit the code after the // Use the response here to do whatever you like with the response. For the purpose of this demo, we are doing two things: 1) logging a message to the console and 2) saving the response data in a variable and showing it above (see the source code of this page to see the very simple implementation).

Then provide this tag with your preferred trigger and save it.

Advanced Setup

You can do even more though. It is possible to trigger a custom event after the response from DecisionRules arrives and use this event as a trigger in GTM. In order to achieve this, you will need to do a couple of other things:

The configuration is done now! We have prepared a GTM with the very same configuration. If you open console on this page, you will be able to see the message from our custom-tag.

How it works

The dr-call tag, which is executed upon initialization, fires a POST request to DecisionRules. When it gets a response, it runs the code below the // Use the response here comment, including the dataLayer.push command. This command does two things at the same time. First, it updates the dr-response-data data layer variable. Second, it fires the custom dr-response event. The event then triggers our custom-tag which logs a message to the console.