This repository has been archived by the owner on May 4, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #999 from uPortal-Project/rely-on-gtm-to-init-ga
Rely on Google Tag Manager to init Google Analytics
- Loading branch information
Showing
5 changed files
with
44 additions
and
15 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
var config = config || {}; | ||
var _gaq = _gaq || []; | ||
|
||
function _gaLt(event){ | ||
var el = event.srcElement || event.target; | ||
|
||
/* Loop up the tree through parent elements if clicked element is not a link (eg: an image in a link) */ | ||
while(el && (typeof el.tagName == 'undefined' || el.tagName.toLowerCase() != 'a' || !el.href)) | ||
el = el.parentNode; | ||
|
||
if(el && el.href){ | ||
if(el.href.indexOf(location.host) == -1 && el.href != 'javascript:;'){ /* external link */ | ||
var eventOptions = {eventCategory: 'Outbound Link', eventAction: el.href, eventLabel : el.text }; | ||
window.ga('send', 'event', eventOptions); | ||
console.log('ga event logged c: Outbound Link a: '+el.href+' l:'+ el.text); | ||
// Click will open in a new window if it is the middle button or the | ||
// meta or control keys are held | ||
var target = (el.target && !el.target.match(/^_(self|parent|top)$/i)) ? el.target : false; | ||
var newWindow = event.button == 1 || event.metaKey || event.ctrlKey || target; | ||
/* HitCallback function to either open link in either same or new window */ | ||
var hitBack = function(link, target){ | ||
target ? window.open(link, target) : window.location.href = link; | ||
}; | ||
|
||
if(newWindow){ | ||
setTimeout(function(){ | ||
window.open(el.href, target); | ||
}.bind(el),500); | ||
/* Prevent standard click */ | ||
event.preventDefault ? event.preventDefault() : event.returnValue = !1; | ||
} | ||
} | ||
|
||
} | ||
} | ||
|
||
/* Attach the event to all clicks in the document after page has loaded */ | ||
var w = window; | ||
w.addEventListener ? w.addEventListener("load",function(){document.body.addEventListener("click",_gaLt,!1)},!1) | ||
: w.attachEvent && w.attachEvent("onload",function(){document.body.attachEvent("onclick",_gaLt)}); |
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
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
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