simpleanalytics / gatsby-plugin Goto Github PK
View Code? Open in Web Editor NEWGatsby plugin for Simple Analytics
Home Page: https://www.npmjs.com/package/gatsby-plugin-simple-analytics
Gatsby plugin for Simple Analytics
Home Page: https://www.npmjs.com/package/gatsby-plugin-simple-analytics
I've set up a Gatsby site and I'm using gatsby-plugin-simple-analytics
. If you go to https://help.workoutscheduler.de/, you can see that the integration code is indeed installed (check the source code and search for /hello.js
).
Unfortunately, Simple Analytics doesn't seem to detect that the tracking code is installed (as shown in screenshot below).
One possible reason I can think of is that the tracking code gets installed in the head
area, while the site may check the body
only.
Something else which might be relevant: I've set up Simple Analytics tracking for workoutscheduler.de
as a different "website". Will the events from "help.workoutscheduler.de" be tracked there as well? Could this be the reason the script on "help.workoutscheduler.de" is not detected?
I can't get the sa_event function to work. Any ideas?
{
resolve: 'gatsby-plugin-simple-analytics',
options: {
// Optional custom domain
domain: 'sa.mydomain.com',
eventsGlobal: 'sa',
events: true,
trackPageViews: true
}
}
const windowGlobal = typeof window !== 'undefined' && window
function () {
windowGlobal.sa_event("click_button")
}
Error: windowGlobal.sa_event is not a function
After setting up the custom subdomain I can't figure out how to add this subdomain to the plugin's options in the gatsby config. Here is your plugin's doc:
If you want to set a custom domain, use this config:
plugins: [
{
resolve: 'gatsby-plugin-simple-analytics',
options: {
eventsGlobal: 'sa',
events: true,
trackPageViews: true,
ignorePages: ['pathname']
}
}
]
And here is my current config for the plugin (which works without subdomain):
{
resolve: "gatsby-plugin-simple-analytics",
options: {
trackPageViews: true,
events: true,
eventsGlobal: "sa_event",
},
},
How can I update it to reflect the new subdomain?
Hey!
I'm going back and adding analytics to some of my older courses which of course need hostname
since they're all on GitHub Pages.
Thanks!
-- Brian
Would it be possible to minify the script in production environments? I think the script just needs to be injected in another way so gatsby can handle the script itself.
<script id="simple-analytics-loader" type="text/javascript" data-loaded="false">!(function(s, i, m, p, l, e) {
const parent = document.querySelector('#simple-analytics-loader');
if (!parent) return;
const dnt = s.doNotTrack || m.doNotTrack || m.msDoNotTrack;
if (/yes|1/.test(dnt) && parent) {
parent.setAttribute('data-enabled', false);
return console.warn('Simple Analytics: Not loading script when doNotTrack is enabled');
}
l = i.createElement(p);
l.addEventListener('load', function() {
if (parent) {
parent.setAttribute('data-loaded', true);
let event;
if (typeof Event === 'function') {
event = new Event('script-loaded');
} else {
event = document.createEvent('Event');
event.initEvent('script-loaded', true, true);
}
parent.dispatchEvent(event);
}
}, false)
l.async = "true";
l.src="https://scripts.simpleanalyticscdn.com/latest.js";
l.type="text/javascript";
l.setAttribute('id', 'simple-analytics');
e = i.getElementsByTagName(p)[0];
e.parentNode.insertBefore(l, e);
})(
window,
document,
navigator,
'script'
)</script></html>
Hi!
I configured the plugin as on documentation, but I am not able to get the sa_event from the window, the auto events works fine.
In gatsby-config.js:
{
resolve: "gatsby-plugin-simple-analytics",
options: {
trackPageViews: true,
events: true,
eventsGlobal: 'sa_event',
},
},
I am using "gatsby": "4.15.2".
Tracking event function implementation:
export const trackEvent = (type: EventType, metadata?: Object) => {
if (window && window.sa_event && metadata != null) {
return window.sa_event(type, metadata);
} else if (window && window.sa_event) {
return window.sa_event(type);
}
return null;
};
What am I doing wrong?
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.