This repository has been archived by the owner on Oct 6, 2024. It is now read-only.
forked from NoMore404/jPlugin-OutBoundLinkTracking
-
Notifications
You must be signed in to change notification settings - Fork 0
/
outboundtracking.php
96 lines (68 loc) · 2.28 KB
/
outboundtracking.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<?php
/**
* @package GA Outbound Click Tracking - Plugin for Joomla 3.0!
* @author No More 404
* @copyright Copyright (c) 2012 NoMore404.nl
* @license MIT license: http://opensource.org/licenses/MIT
*/
defined( '_JEXEC' ) or die( 'Restricted access' );
jimport( 'joomla.plugin.plugin' );
class plgSystemOutboundTracking extends JPlugin {
function plgSystemOutboundTracking(&$subject, $params) {
parent::__construct($subject, $params);
$mode = $this->params->def('mode', 1);
}
function onAfterRender(){
$app =& JFactory::getApplication();
if( $app->isAdmin() ){
return;
}
$GAtrackingcode="";
$outboundtrackingscript="";
$buffer = JResponse::getBody();
$header = explode('</head>',$buffer);
if ($this->params->get('googleid')){
$GAtrackingcode .="
<script type='text/javascript'>
var _gaq = _gaq || [];
_gaq.push(['_setAccount', '".$this->params->get('googleid')."']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>";
}
$outboundtrackingscript .="
<script>
// GA Outbound Cick Tracking - by No More 404
(function($) {
$(function(){
$('a').each( function() {
hostname = new RegExp(location.host);
// Local link...
if(hostname.test( this.href )){
// Do Nothing
}
// Anchor link
else if( this.href.slice(0, 1) == '#'){
// Anchor Event?!
}
// Link not containing current host
else {
$(this).on('click', function(){
_gaq.push(['_trackEvent', 'OutboundLink', 'Click', this.href ]);
});
}
});
});
}(jQuery));
</script>
";
$buffer = preg_replace ("/<\/body>/", "\n".$GAtrackingcode.$outboundtrackingscript."\n</body>", $buffer);
// $buffer = preg_replace ("/<\/head>/", "\n".."\n</head>", $buffer);
JResponse::setBody($buffer);
return;
}
}