Skip to content
All gists
Back to GitHub
Sign in
Sign up
Sign in
Sign up
{{ message }}
Instantly share code, notes, and snippets.
benbalter
/
ga-jetpack-social.php
Last active
Sep 26, 2015
Star
0
Fork
0
Star
Code
Revisions
7
Embed
What would you like to do?
Embed
Embed this gist in your website.
Share
Copy sharable link for this gist.
Clone via HTTPS
Clone with Git or checkout with SVN using the repository’s web address.
Learn more about clone URLs
Download ZIP
Google Analytics Tracking of JetPack (Sharedaddy) Social Engagement
Raw
ga-jetpack-social.php
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
Show hidden characters
<?php
/**
* Plugin Name: Jetpack (Sharedaddy) Google Analytics Tracking
* Description: Allows tracking of Facebook and Twitter shares in Google Analytics Social Tracking
* Author: Benjamin J. Balter
* Author URI: http://ben.balter.com
* Version: 0.1
*/
/**
* Outputs javascript to document head
*/
function
bb_ga_social_footer
() {
?>
<
script
>
jQuery
(
document
)
.
ready
(
function
(
$
)
{
//twitter
$
(
'a.share-twitter'
)
.
click
(
function
(
)
{
_gaq
.
push
(
[
'_trackSocial'
,
'twitter'
,
'share'
,
$
(
this
)
.
attr
(
'href'
)
.
substr
(
0
,
$
(
this
)
.
attr
(
'href'
)
.
indexOf
(
'?'
)
)
]
)
;
}
)
;
//facebook
$
(
'a.share-facebook'
)
.
click
(
function
(
)
{
_gaq
.
push
(
[
'_trackSocial'
,
'faceboook'
,
'share'
,
$
(
this
)
.
attr
(
'href'
)
.
substr
(
0
,
$
(
this
)
.
attr
(
'href'
)
.
indexOf
(
'?'
)
)
]
)
;
}
)
;
}
)
;
</
script
>
<?php
}
//add our hook with higher-than-default priority
add_action(
'wp_footer'
,
'bb_ga_social_footer'
,
20
)
/**
* Require WP to load jQuery if not already loaded
* h/t @Ramoonus
*/
function
bb_ga_social_enqueue
() {
wp_enqueue_script("
jquery
");
}
//add hook to enqueue jQuery on load
add_action(
'init'
,
'bb_ga_social_enqueue'
);
?>
Sign up for free
to join this conversation on GitHub
. Already have an account?
Sign in to comment
You can’t perform that action at this time.
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.