Normally Google conversion code is added in header or footer of the “Thank you for your purchase” pages. A conversion is logged when someone lands on such thank you pages. But what if you want to notify Google about a conversion when a certain event is triggered like Sigup, Buy Now or Register button is clicked. Below is the code that can be used to create event based Google conversion. Now you can call
var google_conversion_id = 1234567890; var google_conversion_language = "en"; var google_conversion_format = "3"; var google_conversion_color = "ffffff"; var google_conversion_label = ""; var google_conversion_value = 0; var conversionLabels = { 'order-success': "conversoin_label_here" }; function trackConversion(label) { google_conversion_label = conversionLabels[label]; document.write = function(text) { $('#content').append(text); }; $.getScript('https://www.googleadservices.com/pagead/conversion.js'); }; /* then somewhere in your ui code: */ trackConversion('order-success'); trackCoversion on any event to trigger Google Conversion.
Trigger Google conversion on some event
Normally Google conversion code is added in header or footer of the “Thank you for your purchase” pages. A conversion is logged when someone lands o
Related posts
Engineering
Random string generator
Learn how to generate random strings in PHP with a simple, reusable function. This guide explains how the generator works, how to create strings of different lengths, common use cases, and secure alternatives using random_bytes() and random_int() for authentication tokens and other security-sensitive applications.
Engineering
MySQL calculate hours since row created
Learn how to calculate the number of hours that have passed since a MySQL row was created. This guide explains how to use TIMESTAMPDIFF() with created_at, compares it with DATEDIFF(), and covers practical examples for calculating hours, minutes, seconds, and records older than a specific time period.
Engineering
Disable Browser's Back button
Learn why you can’t truly disable the browser Back button using JavaScript and how to properly manage app state using the History API, popstate, and bfcache instead.