Overview
This article provides a comprehensive guide on using Google Tag Manager (GTM) to enhance referral workflows by storing referral information and prepopulating forms. It details the process of creating user variables for tracking referral campaigns and share tokens, setting new cookies, and creating custom HTML tags to prepopulate referral fields in external forms. Additionally, it explains how to use the stored data to advance referrals via API.
Information
You can use Google Tag manager to store the referral information that advocates are sharing in the referral workflow! Once you have Google Tag Manager scripts loaded on your site, you will be able to implement form pre-population without any effort from your development team.
- Create "User Variables" for the Referral CampaignID and Infl Share Token
- Create a new Custom HTML "Tag" to set a cookie with the referral information
- Create "User Variables" for the referral information in the cookie
- Prepopulate the form using values from the cookie created in Step 2
- Trigger the Prepopulation tag when the form page is viewed
- Submit and Publish Changes
- Post referral data back to Influitive after form submission
Create "User Variables" for the Referral CampaignID and Infl Share Token
- In the Google Tag Manager workspace, go to "Variables" and add a new variable
- Create a new Variable for Referral CampaignID
- In the variable configuration choose "Query" component type
- Enter "infl_referral_campaign_id" for the query key
- Define a name for this variable that would be recalled upon when creating a tag between "{{}}"
- Create a new Variable for Share Token
- Repeat the above step for creating a user variable for "infl_share_token"
Set new Cookies with the referral information
- In the Google Tag Manager workspace, go to "Tags" and create a new Tag
- Choose "Custom HTML" as the Tag's type
- Settings for the Custom HTML tag:
HTML*:
<script> (function(){ if ("{{infl_share_token}}" != 'undefined' && "{{infl_referral_campaign_id}}" != 'undefined'){ console.log("{{infl_share_token}}"); console.log("{{infl_referral_campaign_id}}"); var cookieName = "infl_referral_campaign_id"; var cookieValue = "{{infl_referral_campaign_id}}"; var otherCookieName = "infl_share_token"; var otherCookieValue = "{{infl_share_token}}"; var cookiePath = "/"; var expirationTime = 2628000; //For example one month in seconds (2628000) expirationTime = expirationTime * 1000; //Convert expirationtime to milliseconds var date = new Date(); //Create javascript date object var dateTimeNow = date.getTime(); //Get current time in milliseconds since 1 january 1970 (Unix time) date.setTime(dateTimeNow + expirationTime); //Set expiration time (Time now + one month) var expirationTime = date.toUTCString(); //Convert milliseconds to UTC time string document.cookie = cookieName+"="+cookieValue+"; expires="+expirationTime+"; path="+cookiePath; //Set cookie document.cookie = otherCookieName+"="+otherCookieValue+"; expires="+expirationTime+"; path="+cookiePath; } })(); </script> <br>
* note this script assumes the cookie expires in a month however can be changed to expire sooner or only for the session. In addition, this step relies on the variables, infl_share_token, and infl_share_id in the previous step.
• Trigger this tag on all page views or where clicks would land with the query string.
Create "User Variables" for the Referral information in the cookie
- In the Google Tag Manager workspace, go to "Variables" and add a new variable
- Create a new Variable for Referral CampaignID
- In the variable configuration choose "1st Party Cookie" component type
- Enter "infl_referral_campaign_id" for the cookie name
- Define a name for this variable that would be recalled in the following step of creating a tag to prepopulate the form
- Create a new Variable for Share Token
- Repeat the above step for creating a user variable for "infl_share_token"
Create a new Custom HTML "Tag" to pre-populate referral fields using the cookie information
- In the Google Tag Manager workspace, go to "Tags" and create a new Tag
- Choose "Custom HTML" as the Tag's type
- Settings for the Custom HTML tag. Ensure you are using the same name for the user variables in the previous step:
HTML*:
<script> (function(){ document.getElementById("referral_campaign_input_id").value = "{{REFERRAL CAMPAIGN VARIABLE NAME}}"; document.getElementById("share_token_input_id").value = "{{SHARE TOKEN VARIABLE NAME}}"; })(); </script><br>
* note this script assumes the form fields have an ID of referral_campaign_id and share_token
Trigger the tag when the form page is viewed
- Setup the tag to be triggered when the form page is viewed
Publish Changes in Google Tag Manager
- When you are finished configuring your variables, tags, and trigger, you can proceed to publish your changes
Post referral data back after the form submission to the Influitive API to advance the referral workflow
- Now that the referral campaign and share token is pre-populated on the form, they can be sent to Influitive's API to advance a referral. Here is the API call to advance a referral via a shared link.
POST /referrals HTTP/1.1 Host: api.influitive.com Content-Type: application/json Accept: application/json Authorization: Token {{YOUR AUTHORIZATION TOKEN HERE}} X_ORG_ID: {{YOUR_ORG_ID HERE}} {"referral": { "prospect": { "email":"{{email address from the form}}", "company":"{{company}}, "title":"{{title}}", ... }, "contact": { "share_token": "{{share token from the form}}" }, "campaign_id":"{{CAMPAIGN ID HERE}}", "status": "{{milestone to be advanced in the referral flow}}" } }
FAQ
How can I use Google Tag Manager to track referral campaign information?
You can track referral campaign information by creating user variables in Google Tag Manager for the Referral CampaignID and Share Token, setting cookies with this information, and then using these variables to prepopulate forms and advance referrals via API.
What are the steps to prepopulate a form with referral information using GTM?
To prepopulate a form, create a new Custom HTML tag in GTM with a script that uses the referral information stored in cookies. Configure the tag to trigger when the form page is viewed, ensuring the form fields have the correct IDs matched in the script.
Can I adjust the cookie expiration set by the GTM script?
Yes, the script sets the cookie to expire in one month by default, but you can adjust this to expire sooner or to last only for the session based on your requirements.
How do I advance a referral using the stored referral information in GTM?
With the referral information prepopulated on the form, you can send the Referral CampaignID and Share Token to Influitive's API to advance a referral using the appropriate API call.
Is it necessary to publish changes in Google Tag Manager for them to take effect?
Yes, after setting up your variables, tags, and triggers in Google Tag Manager, you must publish the changes to make them live and functional on your site.