mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-09-07 21:16:49 +00:00
Adopt Google Analytics 4 tag code
This commit is contained in:
parent
13a895bd2d
commit
f195bfa9f2
@ -17,7 +17,7 @@ exports.name = "google-analytics";
|
|||||||
exports.platforms = ["browser"];
|
exports.platforms = ["browser"];
|
||||||
exports.synchronous = true;
|
exports.synchronous = true;
|
||||||
|
|
||||||
var CONFIG_CONSENT_REQUIRED_TITLE = "$:/config/cookie-consent-required",
|
var CONFIG_CONSENT_REQUIRED_TITLE = "$:/config/cookie-consent-required", // "yes" or "no" (the default)
|
||||||
CONSENT_TITLE = "$:/state/consent-banner/accepted"; // "": undeclared, "yes": accepted, "no": declined
|
CONSENT_TITLE = "$:/state/consent-banner/accepted"; // "": undeclared, "yes": accepted, "no": declined
|
||||||
|
|
||||||
exports.startup = function() {
|
exports.startup = function() {
|
||||||
@ -25,15 +25,16 @@ exports.startup = function() {
|
|||||||
initialiseGoogleAnalytics = function() {
|
initialiseGoogleAnalytics = function() {
|
||||||
console.log("Initialising Google Analytics");
|
console.log("Initialising Google Analytics");
|
||||||
hasInitialised = true;
|
hasInitialised = true;
|
||||||
var gaAccount = $tw.wiki.getTiddlerText("$:/GoogleAnalyticsAccount","").replace(/\n/g,""),
|
var gaMeasurementID = $tw.wiki.getTiddlerText("$:/GoogleAnalyticsMeasurementID","").replace(/\n/g,"");
|
||||||
gaDomain = $tw.wiki.getTiddlerText("$:/GoogleAnalyticsDomain","auto").replace(/\n/g,"");
|
var url ="https://www.googletagmanager.com/gtag/js?id=" + gaMeasurementID;
|
||||||
// Using ga "isogram" function
|
window.dataLayer = this.window.dataLayer || [];
|
||||||
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
|
window.gtag = function() { window.dataLayer?.push(arguments); };
|
||||||
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
|
window.gtag("js",new Date());
|
||||||
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
|
window.gtag("config",gaMeasurementID);
|
||||||
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
|
const scriptElement = window.document.createElement("script");
|
||||||
ga('create',gaAccount,gaDomain);
|
scriptElement.async = true;
|
||||||
ga('send','pageview');
|
scriptElement.src = url;
|
||||||
|
window.document.head.appendChild(scriptElement);
|
||||||
};
|
};
|
||||||
// Initialise now if consent isn't required
|
// Initialise now if consent isn't required
|
||||||
if($tw.wiki.getTiddlerText(CONFIG_CONSENT_REQUIRED_TITLE) !== "yes") {
|
if($tw.wiki.getTiddlerText(CONFIG_CONSENT_REQUIRED_TITLE) !== "yes") {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
title: $:/plugins/tiddlywiki/googleanalytics/readme
|
title: $:/plugins/tiddlywiki/googleanalytics/readme
|
||||||
|
|
||||||
This plugin enables you to use Google Analytics to track access to your online TiddlyWiki document. Based upon the [[official Google code|https://developers.google.com/analytics/devguides/collection/analyticsjs]].
|
This plugin enables you to use Google Analytics to track access to your online TiddlyWiki document.
|
||||||
|
|
||||||
By default, the user is not asked for permission before initialising Google Analytics. This plugin also optionally integrates with the "Consent Banner" plugin (also found in the official plugin library) so that Google Analytics is not initialised until the user grants explicit permission.
|
By default, the user is not asked for permission before initialising Google Analytics. This plugin also optionally integrates with the "Consent Banner" plugin (also found in the official plugin library) so that Google Analytics is not initialised until the user grants explicit permission.
|
||||||
|
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
title: $:/plugins/tiddlywiki/googleanalytics/settings
|
title: $:/plugins/tiddlywiki/googleanalytics/settings
|
||||||
|
|
||||||
You have only two value to set, only first is mandatory:
|
You have only two value to set, only the first is mandatory:
|
||||||
|
|
||||||
# ''[[Google Analytics Account|$:/GoogleAnalyticsAccount]]'': (mandatory) a code of the form `UA-XXXXXX-XX` where X are digits<br/><$edit-text tiddler="$:/GoogleAnalyticsAccount" default="" tag="input"/>
|
# ''[[Google Analytics Measurement ID|$:/GoogleAnalyticsMeasurementID]]'': (mandatory) a code of the form `G-XXXXXXXXXX` where X are digits or uppercase letters<br/><$edit-text tiddler="$:/GoogleAnalyticsMeasurementID" default="" tag="input"/>
|
||||||
|
|
||||||
# ''[[Google Analytics Domain|$:/GoogleAnalyticsDomain]]'': (optional) the website URL where the TiddlyWiki file is published. Defaults to `auto` if not set.<br/><$edit-text tiddler="$:/GoogleAnalyticsDomain" default="" tag="input"/>
|
|
||||||
|
@ -7,7 +7,7 @@ If you don't already have an account:
|
|||||||
# Go to the Google Analytics website: http://www.google.com/analytics/
|
# Go to the Google Analytics website: http://www.google.com/analytics/
|
||||||
# Click the ''Access Google Analytics'' button and follow instructions to set up your account
|
# Click the ''Access Google Analytics'' button and follow instructions to set up your account
|
||||||
# Enter the URL where the wiki is hosted
|
# Enter the URL where the wiki is hosted
|
||||||
# Note the Tracking ID for this domain of the form `UA-XXXXXX-XX`
|
# Note the Tracking ID for this domain of the form `G-XXXXXXXXXX`
|
||||||
|
|
||||||
!! Install the plugin on your local copy of the TiddlyWiki
|
!! Install the plugin on your local copy of the TiddlyWiki
|
||||||
|
|
||||||
@ -20,5 +20,5 @@ If you don't already have an account:
|
|||||||
|
|
||||||
!! Upload the new version of your TiddlyWiki
|
!! Upload the new version of your TiddlyWiki
|
||||||
|
|
||||||
# Upload the saved TiddlyWiki to TiddlySpot, GitHub, GitLab or other web host
|
# Upload the saved TiddlyWiki to Tiddlyhost, GitHub, GitLab or other web host
|
||||||
# Return to your Google Analytics page to check that your site is being tracked
|
# Return to your Google Analytics page to check that your site is being tracked
|
||||||
|
Loading…
Reference in New Issue
Block a user