Inspired by a blog post of Zain Zafar, I implemented my own version of a Google AdWords conversion tracking from AngularJS.
Load the AdWords code from your HTML file:
<script type="text/javascript" src="//www.googleadservices.com/pagead/conversion_async.js"></script>
Then add the AdWords service to your Angular app:
angular.module('adWordsApp').factory('GoogleAdWordsService', function ($window) {
return {
sendBookingConversion: function (conversion_id, conversion_language, conversion_label, conversion_value, conversion_currency) {
var data = {
google_conversion_id: conversion_id,
google_conversion_language: conversion_language,
google_conversion_format: "3",
google_conversion_color: "ffffff",
google_conversion_label: conversion_label,
google_conversion_value: conversion_value,
google_conversion_currency: conversion_currency,
google_remarketing_only: false
};
//alert('call conversion: ' + JSON.stringify(data));
$window.google_trackConversion(data);
}
};
});
The last thing is to call the service from your controller when the conversion happens:
GoogleAdWordsService.sendBookingConversion(12345, 'de', 'TheLabel', 130, 'CHF');
