Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@macbookandrew
Last active September 11, 2017 16:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save macbookandrew/84ce54d73713d82b390fc9dc29b19e12 to your computer and use it in GitHub Desktop.
Save macbookandrew/84ce54d73713d82b390fc9dc29b19e12 to your computer and use it in GitHub Desktop.
Basic Google Analytics tracking for mailto: links
<?php
/**
* Plugin Name: WPAmplify GA Tracking
* Plugin URI: https://gist.github.com/macbookandrew/84ce54d73713d82b390fc9dc29b19e12/
* Description: Basic Google Analytics tracking for mailto: links
* Version: 1.0.0
* Author: AndrewRMinion Design
* Author URI: https://andrewrminion.com
* Copyright: 2017 AndrewRMinion Design
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License, version 2, as
* published by the Free Software Foundation.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
defined( 'ABSPATH' ) or die( 'No access allowed' );
/**
* Add tracking to mailto: links
*/
function wpamplify_ga_script() {
wp_add_inline_script( 'jquery-core', '
(function($) {
$(document).ready(function(){
$("a[href^=\'mailto\']").on("click", ga("send", "event", { eventCategory: "email", eventAction: "click"});)
});
})(jQuery);
' );
}
add_action( 'wp_enqueue_scripts', 'wpamplify_ga_script' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment