Google Adwords Conversion Tracking Event - Single Page

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

I have a client site (wordpress), which is actually one page where it has a contact form below (built using contact form 7, if you need to know).

The contact form is associated only with the anchor ( # ). This is not a separate page.

Code for implementation:

 <!-- 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), as well as on the Internet, I found several 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:

1 - When submitting the form, Tracking_conversion_custom() is called, but since I have one page, will var url = encodeURI(location.href); work as expected regarding Google AdWords tracking? (remember - this is just a binding)

2 - In all the codes that I saw, some vars are missing (for example, var google_remarketing_only = false; or google_conversion_format ) - are they negligible? If not, how to add them?

(A similar question here: Adding Google Conversion code to a WordPress 7 contact form )

+6
source share
1 answer

The encoded URL will be fine. Please note that label and target ID values ​​must be valid values ​​in AdWords. Now this label is optional, so if you don’t specify it in AdWords, you need to remove it from this script (not just pass garbage, as this may lead to poor tracking)

However , he said that if I were to you instead of reinventing the wheel and folding my own code, I would just use the official Google tag, which was specially designed for this kind of use:

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

This page explains what you need to do - this happens in terms of remarketing, but the conversion tag and remarketing tag are basically the same (that’s what “google_remarketing_only” means true / false - you want it to be “false” as this is conversion tracking).

So, you want something like this, and then just call google_trackConversion () whenever the form is submitted - don't mess with the encoding, etc. in 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, eg 100 etc. google_remarketing_only: false }); //]]> 

Hope this helps.

+19
source

Source: https://habr.com/ru/post/973498/


All Articles