Instructions
There are 3 phases for implementing conversion tracking:
- Setting up Google Analytics(GA) site tag
- Persisting Actions Center URL parameter
- Sending Conversion Data
Google Analytics site Tag setup.
Work with you Google contact to generate a Measurement ID
for your Actions Center account.
Add the following code snippet after the head
tags on all web pages
that:
- a conversion can occur
- the landing page for all
action_links
that are Reserve with Google enabled.
No Existing Google Analytics Integration
If this is the first time creating a Google Analytics site(gtag.js), use the following code snippet:
<!-- Global site tag (gtag.js) - Google Analytics --> <script async src="https://www.googletagmanager.com/gtag/js?id=GA_MEASUREMENT_ID_PROVIDED_BY_GOOGLE"></script> <script> window.dataLayer = window.dataLayer || []; function gtag(){dataLayer.push(arguments);} gtag('js', new Date()); gtag('config', 'GA_MEASUREMENT_ID_PROVIDED_BY_GOOGLE', // Replace with Measurement ID { // DO NOT EDIT THE BELOW MENTIONED PARAMETERS // AS OVERRIDING RESULTS IN SENDING US PII INFORMATION. 'referrer' : undefined, 'page_title' : undefined, 'page_path': undefined, 'page_location': undefined, 'send_page_view': false, 'anonymize_ip': true, 'groups': 'reserve_with_google' }); </script>
Existing Google Analytics Integration
If you already have a Google Analytics site tag(gtag.js) for an existing integration, use the following code snippet:
gtag('config', 'GA_MEASUREMENT_ID_PROVIDED_BY_GOOGLE', //Replace with Measurement ID { 'referrer' : undefined, 'page_title' : undefined, 'page_path': undefined, 'page_location': undefined, 'send_page_view': false, 'anonymize_ip': true, 'groups': 'reserve_with_google' });
Update the above mentioned code snippets with the generated Measurement ID for your account.
Persisting Actions Center URL Parameter
To properly track conversions from action link
(s), Google will
set a URL parameter rwg_token
, which should be returned at the
time of a conversion.
You will be required to persist the rwg_token
URL parameter
which will be appended to all action links provided by you for a maximum
duration of 30 days when a user visits the landing page via Google. The
preferred way to persist this information is via cookies.
- Add the following script on the landing page for all your
action_link
(s) that are Actions Center enabled. - Update the rootdomain with your domain.
<script> var query = location.search.substring(1); var params = query.split('&'); var rwg_token = undefined; for (var i = 0; i < params.length; ++i) { var pair = params[i].split('='); if (pair[0] == 'rwg_token') { rwg_token = decodeURIComponent(pair[1]); break; } } if (typeof rwg_token == 'undefined') { document.cookie = "_rwg_token=" + rwg_token + ";max-age=2592000;domain=rootdomain.com;path=/"; } </script>
Sending Conversion Data
When a user completes a transaction which originated from a Google Place Action link, you need to trigger the code mentioned below in order to complete conversion tracking.
<script> function getCookie(cname) { var name = cname + "="; var decodedCookie = decodeURIComponent(document.cookie); var ca = decodedCookie.split(';'); for(var i = 0; i <ca.length; i++) { var c = ca[i]; while (c.charAt(0) == ' ') { c = c.substring(1); } if (c.indexOf(name) == 0) { return c.substring(name.length, c.length); } } return ""; } if (leadFromReserveWithGoogle()) { // implement a function to identify the conversion is originating via Google gtag('event', 'rwg_conversion', { 'rwg_token': getCookie('_rwg_token'), 'send_to': 'reserve_with_google' }); } </script>