simpleanalytics / scripts Goto Github PK
View Code? Open in Web Editor NEWOpen Source Public Scripts for Simple Analytics
Home Page: https://www.simpleanalytics.com
License: MIT License
Open Source Public Scripts for Simple Analytics
Home Page: https://www.simpleanalytics.com
License: MIT License
Hey guys
I'm trying to setup analytics on a website but it seems like the url of simple analytics is hardcoded in the library. I can do a PR myself but I do know where to find the source code for the npm package.
Thanks in advance
Tim
My Sentry is showing errors thrown in the SA script, looks like it's this line:
Line 484 in ed9efd1
Here's a link to the Sentry issue:
https://sentry.io/share/issue/20005bc054fb4e48a65b8c01209ae3d2/
We send a session id with events, but it makes sense to send it with page views as well.
That way we can link events (that happen on one page or multiple in a SPA) to a page view.
Add this for iOS:
And this for desktop:
window.navigator._duckduckgoloader_
Sometimes you don't want to skip the Simple Analytics on local scripts. For example with Chrome extensions.
I am currently trying to collect some usage information about a chrome extension using SimpleAnalytics - is that possible?
I want to track some events in the extension popup-window (that appears when clicking the extension icon in the top right). This extension popup is hosted by Chrome on "chrome-extension://[Random extension ID]/popup.html" so I used the "data-hostname" argument to set the hostname to another custom URL that I created for this extension.Using this technique, Simple Analytics is still logging "Simple Analytics: Not sending request from [Random extension ID here]". It looks like the random extension ID is triggering the localhost detection as "locationHostname.indexOf(".") == -1" will eval to true. Is there a way to disable this check or any other recommendations when using for extensions?
Lines 367 to 374 in 3b270ce
Let's make this optional via data-force=true
, data-force-run=true
, or data-always-run=true
. Force makes the most sense to me because we then also can bypass the check if the script is loaded twice. Maybe some people want to load our script multiple times.
Instead of using this:
Lines 287 to 288 in 3b270ce
We can use:
var scriptElement = doc.currentScript || doc.querySelector('script[src*="' + baseUrl + '"]');
We use onClick
when somebody clicks a link. We only set this when there is no onClick
handler set. But for some frameworks like Next.js all links have onClick
events.
Lines 149 to 185 in ed9efd1
To not overwrite that behavior we can attach an additional event that does not wait for our request to be done:
if (!link.getAttribute("onclick")) {
// current code
} else {
// new code
link.on('click', function() {
// current code
})
}
Why not always use the second method? Well, we want to wait for the event to be sent to our server before sending the user to the next page. So it's a backup method.
cc CH
Hi there,
I Was looking at your code and saw that:
scrolled = window.setTimeout(position, 500);
Line 337 in 7a93d22
setTimeout
returns a TimeoutID, that we can pass to clearTimeout
to cancel the future call. So it won't do what you think.
You may want to do:
window.setTimeout(function () {
scrolled = position()
}, 500);
Anyway, great product!
Line 147 in a4d228d
In the following line, it would be nicer to use window.addEventListener('hashchange', hashHandler, false);
instead of window.onhashchange = hashHandler
, because it plays nicer with other code:
Line 349 in 5d7426f
It just took me way longer than I care to admit to debug an issue caused by this, which only occurred in production, since my dev-builds don't use the analytics script.
Hello,
The constructor new Event()
is not supported in Internet Explorer, and this is causing scripts to break when they use history.pushState()
. It looks like you are checking that Event
is defined before trying to use the constructor, but Event
is defined in IE, just not as a function.
There are a couple of possible solutions that come to mind: polyfilling or substituting the constructor somehow, or checking not just that Event
is defined, but that it is defined as a function.
Thanks,
Jonathan Sutcliffe
(navigator.brave && await navigator.brave.isBrave() || false)
Original: simpleanalytics/roadmap#609
From a very helpful customer, we got this error report:
The following is logged to console:
Simple Analytics: Uncaught TypeError: Illegal invocation
At this stage, it seems exclusively happening on Chrome/Windows.
Good read: https://xgwang.me/posts/you-may-not-know-beacon/
It does suggest that if a URL has an error, sendBeacon
will throw "TypeError: Illegal invocation".
This also seemed to effect the next.js project as well: vercel/next.js#23856 (fix: https://github.com/vercel/next.js/pull/26601/files)
Maybe with domains separated? data-hostname="example.com,example2.com"
or data-extra-domains="example.com"
so customers don't have to type their domain.
Detect this as a bot.
cc @Kilian
There are bots that overwrite random, let's run a test to see if they do:
const bot = Math.random() === Math.random();
When retrieving the following Simple Analytics file via my custom CNAME:
https://sa.example.com/v8/app.jsThis file has an embedded "sourceMappingURL" set to "v8.js.map", which does not exist. It seems like this should point to "app.js.map", which does exist. Currently this results in a console warning.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.