Last active
September 11, 2017 16:29
-
-
Save macbookandrew/84ce54d73713d82b390fc9dc29b19e12 to your computer and use it in GitHub Desktop.
Basic Google Analytics tracking for mailto: links
This file contains 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 | |
/** | |
* 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