Last active
December 7, 2017 06:16
-
-
Save nikcree/2c955b999df1fbabe61e9cf8493b3603 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
* Google Phone Tracking For Google Adwords In A Genesis Child Theme. | |
* | |
* Step 1. | |
* Add this snippet into the Functions File, then ... | |
* | |
* Step 2. | |
* Replace all instance of the phone number (07) 1234 5678 ans =671712345678 | |
* with the phone number you want to use. | |
* | |
* Step 3. | |
* Add the following html anywhere in the website you need to track the phone number | |
* <a id="googlenumber" class="phone" href="tel:+61712345678">07 1234 5678</a> | |
* | |
*/ | |
//* Google Phone Conversion Tracking | |
add_action('wp_head', 'posbiz_google_dynamic_phone_number_tracking'); | |
function posbiz_google_dynamic_phone_number_tracking() { ?> | |
<!-- Google Phone Conversion Tracking Script goes here --> | |
<?php } | |
//* Google Tracking Number Dynamic Replacement | |
add_action('wp_head', 'posbiz_google_dynamic_phone_number_replacement'); | |
function posbiz_google_dynamic_phone_number_replacement() { ?> | |
<script type="text/javascript"> | |
var callback = function(formatted_number, mobile_number) { | |
// formatted_number: number to display, in the same format as | |
// the number passed to _googWcmGet(). | |
// (in this case, '07 1234 5678') | |
// mobile_number: number formatted for use in a clickable link | |
// with tel:-URI (in this case, '+61712345678') | |
var e = document.getElementById("googlenumber"); | |
e.href = "tel:" + mobile_number; | |
e.innerHTML = ""; | |
e.appendChild(document.createTextNode(formatted_number)); | |
}; | |
</script> | |
<?php } | |
//* Google Dynamic Tracking Number | |
add_filter( 'genesis_attr_body', 'posbiz_custom_attributes_body' ); | |
function posbiz_custom_attributes_body( $attributes ) { | |
$attributes['onload'] = "_googWcmGet(callback, '07 1234 5678')"; | |
return $attributes; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment