Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google Adwords conversion Tracking event - single page

I am very unfamiliar with all the google anaylytics / adwords / conversion etc ..

I have a client site ( wordpress ) , which is actually a single page , where it has a contact form at the bottom ( built with contact form 7 if one must know ).

The contact form is linked with an anchor ( # ) only. it is not a separate page.

The code for implementing is :

<!-- Google Code for Conversion Page -->
<script type="text/javascript">
/* <![CDATA[ */
var google_conversion_id = 010101010101;
var google_conversion_language = "en";
var google_conversion_format = "2";
var google_conversion_color = "ffffff";
var google_conversion_label = "SomeRandomLabel";
var google_remarketing_only = false;
/* ]]> */
</script>
<script type="text/javascript" src="//www.googleadservices.com/pagead/conversion.js">
</script>
<noscript>
<div style="display:inline;">
<img height="1" width="1" style="border-style:none;" alt="" src="//www.googleadservices.com/pagead/conversion/971631980/?label=MCwlCLTErgoQ7NqnzwM&amp;guid=ON&amp;script=0"/>
</div>
</noscript>

After reading a lot of questions here ( Like this ) , and also on the web, I have found some codes and hacked them into this :

<script type="text/javascript">
/* <![CDATA[ */
function Tracking_conversion_custom(){
var img = document.createElement("img");
var goalId = 010101010101;
var randomNum = new Date().getMilliseconds();
var value = 0;
var label = "SomeRandomLabel";
var url = encodeURI(location.href);

var trackUrl = "http://www.googleadservices.com/pagead/conversion/"+goalId+"/?random="+randomNum+"&value="+value+"&label="+label+"&guid=ON&script=0&url="+url;
img.src = trackUrl;
document.body.appendChild(img);
}
/* ]]> */
</script>

<script type="text/javascript" src="//www.googleadservices.com/pagead/conversion.js">
</script>

My Questions are :

1 - The Tracking_conversion_custom() is invoked upon sending the form, but since I have a single page , will var url = encodeURI(location.href); work as expected as far as the google adwords tracking concern ? ( remember - it is an anchor only )

2 - In all the codes I have seen, the some vars are missing ( like var google_remarketing_only = false;, or google_conversion_format) - are they neglectable ? If not - how to add them ?

( Similar question here :Adding Google Conversion code to WordPress Contact Form 7 )

like image 604
Obmerk Kronen Avatar asked Aug 07 '14 15:08

Obmerk Kronen


1 Answers

The encoded URL will be fine. Note that the label and goalID values will need to be the correct values from AdWords - label is now optional though so if one isn't provided in AdWords you'll need to remove it from this script (dont just pass garbage as that may lead to bad tracking)

However, this said if I were you rather than re-inventing the wheel and rolling my own code, I would just use the official Google tag that was designed specifically for this sort of usage:

https://developers.google.com/adwords-remarketing-tag/asynchronous/

That page explains what you need to do - it is coming from a remarketing perspective, but the conversion tag and the remarketing tag are basically the same thing (that is what the "google_remarketing_only" true/false is about - you'll want it to be "false" as this is conversion tracking).

So you'll want something like this, then just call google_trackConversion() whenever the form gets submitted - no messing about with encoding etc this way:

<!-- Put this script in your <head> -->
<script type="text/javascript" src="http://www.googleadservices.com/pagead/conversion_async.js" charset="utf-8"></script>

<!-- the rest of your web page as usual etc -->

<!-- Call this function when the form submits -->
<script type="text/javascript">
/* <![CDATA[ */
window.google_trackConversion({
  google_conversion_id: 123456789, 
  google_conversion_label: abcdefghijkl,  // if provided, remove this line if not provided
  google_conversion_value: 0,  // or the dollar value of this conversion, e.g. 100 etc.
  google_remarketing_only: false
});
//]]>

Hope that helps.

like image 149
matt1 Avatar answered Oct 13 '22 01:10

matt1