diff --git a/README.md b/README.md index 0f0fce3..2508dcc 100644 --- a/README.md +++ b/README.md @@ -57,6 +57,36 @@ Send your custom tags to Loggly by setting the `tag` property. ```Javascript _LTracker.push({ + 'logglyKey': '8c518f97-e3e0-4bfb-a8ed-582d084a5289', + 'sendConsoleErrors' : true, 'tag' : 'tag1,tag2' }); ``` + +Setup Proxy for Ad blockers +---------- +You can proxy the requests from your own domain if the script or its requests are blocked by Ad blockers. To do this, you need to perform following steps + +Set `useProxyDomain` property to true + +```Javascript +_LTracker.push({ + 'logglyKey': '8c518f97-e3e0-4bfb-a8ed-582d084a5289', + 'sendConsoleErrors' : true, + 'tag' : 'javascript-logs', + 'useDomainProxy' : true +}); +``` + +Use the following configuration on your server to forward the requests to Loggly + +``` +#Proxy to Loggly +location /loggly/ { + rewrite ^/loggly/(.*)$ /$1 break; # remove the '/loggly' part from the path, leaving /inputs/xxxxxxxx-xxxx-.../tag/xxx + proxy_set_header Host logs-01.loggly.com; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $remote_addr; + proxy_pass http://logs-01.loggly.com; +} +``` diff --git a/src/loggly.tracker.js b/src/loggly.tracker.js index 764e80d..5ca3aaa 100644 --- a/src/loggly.tracker.js +++ b/src/loggly.tracker.js @@ -3,6 +3,7 @@ LOGGLY_COLLECTOR_DOMAIN = 'logs-01.loggly.com', LOGGLY_SESSION_KEY = 'logglytrackingsession', LOGGLY_SESSION_KEY_LENGTH = LOGGLY_SESSION_KEY.length + 1; + LOGGLY_PROXY_DOMAIN = 'loggly'; function uuid() { // lifted from here -> http://stackoverflow.com/questions/105034/how-to-create-a-guid-uuid-in-javascript/2117523#2117523 @@ -14,8 +15,9 @@ function LogglyTracker() { this.key = false; - this.sendConsoleErrors = false; + this.sendConsoleErrors = false; this.tag = 'jslogger'; + this.useDomainProxy = false; } function setKey(tracker, key) { @@ -28,6 +30,12 @@ tracker.tag = tag; } + function setDomainProxy(tracker, useDomainProxy){ + tracker.useDomainProxy = useDomainProxy; + //refresh inputUrl value + setInputUrl(tracker); + } + function setSendConsoleError(tracker, sendConsoleErrors) { tracker.sendConsoleErrors = sendConsoleErrors; @@ -53,12 +61,25 @@ } function setInputUrl(tracker) { - tracker.inputUrl = LOGGLY_INPUT_PREFIX - + (tracker.logglyCollectorDomain || LOGGLY_COLLECTOR_DOMAIN) - + '/inputs/' - + tracker.key - + '/tag/' - + tracker.tag; + + if(tracker.useDomainProxy == true){ + tracker.inputUrl = LOGGLY_INPUT_PREFIX + + window.location.host + + '/' + + LOGGLY_PROXY_DOMAIN + + '/inputs/' + + tracker.key + + '/tag/' + + tracker.tag; + } + else{ + tracker.inputUrl = LOGGLY_INPUT_PREFIX + + (tracker.logglyCollectorDomain || LOGGLY_COLLECTOR_DOMAIN) + + '/inputs/' + + tracker.key + + '/tag/' + + tracker.tag; + } } LogglyTracker.prototype = { @@ -88,7 +109,7 @@ data = { 'text': data }; - } else { + } else { if(data.logglyCollectorDomain) { self.logglyCollectorDomain = data.logglyCollectorDomain; return; @@ -97,11 +118,14 @@ if(data.sendConsoleErrors !== undefined) { setSendConsoleError(self, data.sendConsoleErrors); } - - + if(data.tag) { setTag(self, data.tag); } + + if(data.useDomainProxy){ + setDomainProxy(self, data.useDomainProxy); + } if(data.logglyKey) { setKey(self, data.logglyKey);