- Joined
- Sep 15, 2014
- Messages
- 4,358
- Likes
- 8,865
- Degree
- 8
Here is a quick jQuery script that automatically adds the UTM stuff to all outbound links:
--
Why do you need this? My domain doesn't send referring data, so all traffic would be considered "direct" in all outbound link's analytics.
Potential Abuse? Yeah - lot of potential abuse, that's why Google Analytics referral spam still exists.
Code:
<script src="https://code.jquery.com/jquery-3.3.1.js" integrity="sha256-2Kok7MbOyxpgUVvAk/HJ2jigOSYS2auK4Pfzbm7uH60=" crossorigin="anonymous"></script>
<script type="text/javascript">
// This script adds UTM variables so outbound links can be tracked
// (SERPWoo.com doesn't send referring data by default, so traffic would appear as direct - this fixes that)
$(document).ready(function(){
//Need to change this to match within the div path you want to restrict this to
$(".article a").each(function() {
var $this = $(this);
var _href = $this.attr("href");
var anchor_text = encodeURIComponent($this.text());
var current_page = window.location.href.toString().split(window.location.host)[1];
//skips if within my domain
if (_href.indexOf(window.location.host) != -1) { return; }
//skips if not http or https (example: "FTP:" or "mailto:" or an absolute '/blog' scenario)
if ((_href.indexOf('http://') == -1) && (_href.indexOf('https://') == -1)) { return; }
$this.attr("href", _href + '?utm_source=SERPWoo.com&utm_medium=referral&utm_term=' + anchor_text + '&utm_content=' + current_page + '&utm_campaign=SERPWooBlog');
//console.log('link_updated:' + _href);
});
});
</script>
--
Why do you need this? My domain doesn't send referring data, so all traffic would be considered "direct" in all outbound link's analytics.
Potential Abuse? Yeah - lot of potential abuse, that's why Google Analytics referral spam still exists.