Si intentamos hacer Tracking de llamadas (tracking calls) con Google desde wordpres podemos utilzar el plugin Google AdWords Website Call Conversions , pero tiene un fallo que podemos corregir de manera fácil.ç

 

en el fichero: google-adwords-website-call-conversions/public/class-gawcc-callrail.php

Debemos cambiar

$content = str_replace( $foundnumber, ‘<span class=”myNumber“>’ . $foundnumber . ‘</span>’, $content );

$footerscript = “<!– CallRail GAWCC WordPress Integraton –><script type=’text/javascript’>window.onload=function(){_googWcmGet(‘myNumber‘, ‘” . $this->options[‘phone’] . “‘);};</script>”;

Dónde myNumber antes tenia escrito gawcc-swap-number

 

Podéis cambiar el contenido completo del fichero por este:

<?php
/**
* Google AdWords Website Call Conversions
*
* @package GAWCC_CallRail
* @author Cliff Seal <cliff@logoscreative.co>
* @link http://callrail.com
* @copyright 2014 CallRail
*/

/**
* Plugin class. This class should ideally be used to work with the
* public-facing side of the WordPress site.
*
* If you're interested in introducing administrative or dashboard
* functionality, then refer to `class-plugin-name-admin.php`
*
* @package GAWCC_CallRail
* @author Cliff Seal <cliff@logoscreative.co>
*/
class GAWCC_CallRail {

/**
* Plugin version, used for cache-busting of style and script file references.
*
* @since 1.0.0
*
* @var string
*/
const VERSION = '1.0.0';

/**
* @TODO - Rename "plugin-name" to the name of your plugin
*
* Unique identifier for your plugin.
*
*
* The variable name is used as the text domain when internationalizing strings
* of text. Its value should match the Text Domain file header in the main
* plugin file.
*
* @since 1.0.0
*
* @var string
*/
protected $plugin_slug = 'gawcc-callrail';

/**
* Instance of this class.
*
* @since 1.0.0
*
* @var object
*/
protected static $instance = null;

/**
* Initialize the plugin by setting localization and loading public scripts
* and styles.
*
* @since 1.0.0
*/
private function __construct() {

// Load plugin text domain
add_action( 'init', array( $this, 'load_plugin_textdomain' ) );

// Activate plugin when new blog is added
add_action( 'wpmu_new_blog', array( $this, 'activate_new_site' ) );

// Notify user to input some settings
add_action( 'admin_notices', array( $this, 'single_activate_notice' ) );

// Echo AdWords snippet to head
add_action( 'wp_head', array( $this, 'adwords_script_echo' ) );

// Execute _googWcmGet && echo CallRail script to footer _late_
add_action( 'wp_footer', array( $this, 'googwcmget_callrail_script_echo' ), 999 );

// Filter ALLTHETHINGS™ to wrap the phone number in spans
add_filter( 'the_content', array ( $this, 'phone_filter' ) );
add_filter( 'the_content_feed', array ( $this, 'phone_filter' ) );
add_filter( 'the_excerpt', array ( $this, 'phone_filter' ) );
add_filter( 'the_excerpt_rss', array ( $this, 'phone_filter' ) );
// Note: no need for title_rss because it's already been filtered: http://codex.wordpress.org/Plugin_API/Filter_Reference#Database_Reads
add_filter( 'the_title', array ( $this, 'phone_filter' ) );
add_filter( 'widget_title', array ( $this, 'phone_filter' ) );
add_filter( 'widget_text', array ( $this, 'phone_filter' ) );
add_filter( 'widget_content', array ( $this, 'phone_filter' ) );
add_filter( 'comment_text', array ( $this, 'phone_filter' ) );

}

/**
* Return the plugin slug.
*
* @since 1.0.0
*
* @return Plugin slug variable.
*/
public function get_plugin_slug() {
return $this->plugin_slug;
}

/**
* Return an instance of this class.
*
* @since 1.0.0
*
* @return object A single instance of this class.
*/
public static function get_instance() {

// If the single instance hasn't been set, set it now.
if ( null == self::$instance ) {
self::$instance = new self;
}

return self::$instance;
}

/**
* Fired when the plugin is activated.
*
* @since 1.0.0
*
* @param boolean $network_wide True if WPMU superadmin uses
* "Network Activate" action, false if
* WPMU is disabled or plugin is
* activated on an individual blog.
*/
public static function activate( $network_wide ) {

if ( function_exists( 'is_multisite' ) && is_multisite() ) {

if ( $network_wide ) {

// Get all blog ids
$blog_ids = self::get_blog_ids();

foreach ( $blog_ids as $blog_id ) {

switch_to_blog( $blog_id );
self::single_activate();

restore_current_blog();
}

} else {
self::single_activate();
}

} else {
self::single_activate();
}

}

/**
* Fired when the plugin is deactivated.
*
* @since 1.0.0
*
* @param boolean $network_wide True if WPMU superadmin uses
* "Network Deactivate" action, false if
* WPMU is disabled or plugin is
* deactivated on an individual blog.
*/
public static function deactivate( $network_wide ) {

if ( function_exists( 'is_multisite' ) && is_multisite() ) {

if ( $network_wide ) {

// Get all blog ids
$blog_ids = self::get_blog_ids();

foreach ( $blog_ids as $blog_id ) {

switch_to_blog( $blog_id );
self::single_deactivate();

restore_current_blog();

}

} else {
self::single_deactivate();
}

} else {
self::single_deactivate();
}

}

/**
* Fired when a new site is activated with a WPMU environment.
*
* @since 1.0.0
*
* @param int $blog_id ID of the new blog.
*/
public function activate_new_site( $blog_id ) {

if ( 1 !== did_action( 'wpmu_new_blog' ) ) {
return;
}

switch_to_blog( $blog_id );
self::single_activate();
restore_current_blog();

}

/**
* Get all blog ids of blogs in the current network that are:
* - not archived
* - not spam
* - not deleted
*
* @since 1.0.0
*
* @return array|false The blog ids, false if no matches.
*/
private static function get_blog_ids() {

global $wpdb;

// get an array of blog ids
$sql = "SELECT blog_id FROM $wpdb->blogs
WHERE archived = '0' AND spam = '0'
AND deleted = '0'";

return $wpdb->get_col( $sql );

}

/**
* Fired for each blog when the plugin is activated.
*
* @since 1.0.0
*/
private static function single_activate() {
// No need to do anything here, methinks
}

/**
* Fired for each blog when the plugin is activated.
*
* @since 1.0.0
*/
public function single_activate_notice() {

if ( get_option( 'gawcc_callrail_settings' ) === false ) {

$viewing = get_current_screen();

if ( $viewing->id !== 'settings_page_gawcc-callrail' ) {

echo '<div class="updated"><p>To get Google AdWords Website Call Conversions set up, please head over to the <a href="options-general.php?page=gawcc-callrail">settings area</a>.</p></div>';

}

}
}

/**
* Fired for each blog when the plugin is deactivated.
*
* @since 1.0.0
*/
private static function single_deactivate() {
// No need to do anything here, methinks
}

/**
* Load the plugin text domain for translation.
*
* @since 1.0.0
*/
public function load_plugin_textdomain() {

$domain = $this->plugin_slug;
$locale = apply_filters( 'plugin_locale', get_locale(), $domain );

load_textdomain( $domain, trailingslashit( WP_LANG_DIR ) . $domain . '/' . $domain . '-' . $locale . '.mo' );
load_plugin_textdomain( $domain, FALSE, basename( plugin_dir_path( dirname( __FILE__ ) ) ) . '/languages/' );

}

/**
* Echo the AdWords script to the footer
*
* @since 1.0.0
*/
public function adwords_script_echo() {

$this->options = (array) get_option( 'gawcc_callrail_settings' );

if ( isset($this->options['adwords']) && $this->options['adwords'] ) {
if ( strpos( $this->options['adwords'], '<script' ) === false ) {
echo '<script type="text/javascript">'. $this->options['adwords'] . '</script>';
} else {
echo $this->options['adwords'];
}

}
}

/**
* Echo the scripts _late_
*
* @since 1.0.0
*/
public function googwcmget_callrail_script_echo() {

$this->options = (array) get_option( 'gawcc_callrail_settings' );

if ( isset($this->options['phone']) && $this->options['phone'] ) {

$footerscript = "<!-- CallRail GAWCC WordPress Integraton --><script type='text/javascript'>window.onload=function(){_googWcmGet('myNumber', '" . $this->options['phone'] . "');};</script>";

if ( isset($this->options['callrail']) && $this->options['callrail'] ) {

$footerscript .= "<script type='text/javascript' src='//cdn.callrail.com/companies/" . str_replace('x', '/', $this->options['callrail']) . "/11/swap.js'></script>";

}

echo $footerscript;

}

}

/**
* Filter for the given phone number
*
* @since 1.0.0
*/
public function phone_filter( $content ) {

// Get the options
$this->options = (array) get_option( 'gawcc_callrail_settings' );

// If a phone number has been set in Settings
if ( isset($this->options['phone']) && $this->options['phone'] ) {

// Strip out punctuation and get the last 8 digits
$strippattern = '/[^0-9]/';
$cleanphonenumber = preg_replace( $strippattern, '', $this->options['phone'] );
$cleanphonenumber = substr($cleanphonenumber, -8);

// Find all phone numbers in the content
$phonepattern = '/\+?[0-9 ()\.\-]{8,21}[0-9]/';
preg_match_all($phonepattern, $content, $matches);

if ( $matches[0] ) {

// Iterate through results
foreach ( $matches[0] as $foundnumber ) {

// Clean integers to ensure a good compare
$cleanedfoundnumber = preg_replace( $strippattern, '', $foundnumber );

// If the number in settings matches the found number...
if ( strpos($cleanedfoundnumber, $cleanphonenumber) !== false ) {

// ...wrap the number in a special span
$content = str_replace( $foundnumber, '<span class="myNumber">' . $foundnumber . '</span>', $content );

}

}

}

}

return $content;

}

}
Track calls to a phone number on a website
Etiquetado en:        

Deja un comentario

A %d blogueros les gusta esto: