Google remarketing with Drupal webforms

By
Santiago Ervina's picture
Santiago Ervina
· 04/05/2016

Google remarketing is a powerful tool for displaying AdWords ads to visitors to our web site based on a set of rules that can be customized.

The drupal webform module is one of the most used, especially to create contact forms, information requests, registrations, etc.
In this article we will explain how to make a module that allows us to remarket to users who have submitted a form with a specific value selected, which will create a callback in our module responsible for creating the webform submission confirmation url, including only a single parameter of product, service or topic on which we want to remarket.  We will use as an example a webform that has a product selection component in which there are 3 options:

1 | Premium
2 | Advanced
3 | Basic

The aim is for the webform submission confirmation page to include the selection code for which the user has requested information, so that we can configure our AdWords product knowing what the user is interested in.
To do this, we will set a confirmation page with a fixed part and a second dynamic part, including the selected product from the webform, so the possible URLs in our example would be:

/envio-realizado/1
/envio-realizado/2
/envio-realizado/3

We must additionally configure the webform to use a custom URL that we create as the confirmation page and add it to the parameters that the user has selected on the form.

The first thing to do is create the module, in Drupal's hook_menu, which will provide a custom URL and callback to handle these requests. We will call our example "webform_remarketing."

/**
 * Implements hook_menu().
 */
function webform_remarketing _menu() {
  $items = array();
  $items['envio-realizado/%'] = array(
    'title' => 'Submission received',
    'description' => 'Confirmation page for webform',
    'page callback' => 'webform_remarketing _confirmation_page',
    'page arguments' => array(1),
    'access arguments' => array('access content'),
  );
  return $items;
}

Once we have created the menu, we need to add the function defined in the callback page that will provide the content for display on screen:

/**
 * Confirmation page menu callback.
 */
function webform_remarketing _confirmation_page ($producto) {
  return . t('Submission received') . ;
}

This function is an example for teaching purposes, so it just shows a simple message.  Logically, it's common to want to show more content, so it's good to remember that all content displayed to the user should use a theming feature so it can be easily modified by the site developer.

The next step we need to take is to modify the configuration webform to use the confirmation page that we created in our module and pass the value selected by the user.  To do this, edit the webform options in the "form settings" tab.  Among other options, there is a section called "address redirection" which offers 3 options.  We need to select "Custom URL" and enter the URL that we defined in our module and make the webform correctly pass to the second part of the URL the value set by the user in the product selection component.  For this we use the corresponding token, which in this case would be [submission: values :?] where the “?” must be replaced by the form_key of the component.   Assuming that the value is “product," what we should put in this field would be:

envio-realizado/[submission:values:producto]

With this, we have achieved our goal.  When a user fills out the form and requests information about a product, the confirmation URL includes the code for that product, so we can configure remarketing using these URLs in AdWords and set our campaigns.

Share 

Related works

Fun musical spanish
Sports Events Pictures
How can we help?Get in touch