Hi,
I have coded something poorly to track conversions with Google AdWords in the footer of file templates/protostar/index.php.
Below is a snippet that I use. It tracks conversions from shopping ads that are based on price feeds for Google Merchants.
The idea is to generate conversions inside AdWords. Each conversion is a JavaScript snippet.
To my understanding, they each differ only in the google_conversion_label that is used twice (once in .js, once for the image tracker).
That snippet goes into the $map array. I have padded mine with xxx so that someone who uses the snippet does not cross-fire easily.
Improvement suggestions welcome e. g. on how to tap into the controller for the language-independent, generic triggers.
best regards - Klaus
<?php
$map = array (
'/component/users/?view=registration&layout=complete' => '5SwhCJrl52wQ6YjR9wMxxx', // register user 2 (submitted)
// '/component/users/?view=registration' => 'pC9yCJfl52wQ6YjR9wMxxx', // register user 1 (input)
'component/users/?task=registration.activate&token=' => 'qDV5CKDl52wQ6YjR9wMxxx', // register user 3 (confirmed)
'/component/users/profile.html' => 'fIlYCOHk52wQ6YjR9wMxxx', // login
'/warenkorb-anzeigen.html' => 'Q4TVCOCUgG0Q6YjR9wMxxx', // go to cart ??? German only - generic one ???
'/zur-kasse-gehen.html' => 'K71SCNqj_GwQ6YjR9wMxxx', // checkout 1
'/checkout/task-step/step-2.html' => 'DGFNCOaj_GwQ6YjR9wMxxx', // checkout 2
'/checkout/task-step/step-3.html' => 'rfWyCOmj_GwQ6YjR9wMxxx', // checkout 3
'/checkout/task-step/step-4.html' => '9VQYCNitgG0Q6YjR9wMxxx', // checkout 4
// '/xxx/' => 'GMBBCJergG0Q6YjR9wMxxx', // paid
);
$uri = $_SERVER['REQUEST_URI'];
$found = false;
foreach($map as $key=>$value) {
if (strpos($uri, $key) !== false) { $found = true; break; };
};
if($found) {
?>
<!-- Google Code for ... Conversion Page -->
<script type="text/javascript">
/* <![CDATA[ */
var google_conversion_id = 1056195689;
var google_conversion_language = "en";
var google_conversion_format = "3";
var google_conversion_color = "ffffff";
var google_conversion_label = "<?= $map[$key] ?>";
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/1056195689/?label=<?= $map[$key] ?>&guid=ON&script=0"/>
</div>
</noscript>
<?php
}
?>