mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-11-23 10:07:19 +00:00
Update to Google Analytics 4 (#7554)
* Adopt Google Analytics 4 tag code * Fix typo * Temporarily add Google Analytics tracking to tw5.com So that we can test everything is working with the Vercel preview * Remove test configuration
This commit is contained in:
parent
a05302da10
commit
9b8db5dbb1
@ -17,7 +17,7 @@ exports.name = "google-analytics";
|
||||
exports.platforms = ["browser"];
|
||||
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
|
||||
|
||||
exports.startup = function() {
|
||||
@ -25,15 +25,16 @@ exports.startup = function() {
|
||||
initialiseGoogleAnalytics = function() {
|
||||
console.log("Initialising Google Analytics");
|
||||
hasInitialised = true;
|
||||
var gaAccount = $tw.wiki.getTiddlerText("$:/GoogleAnalyticsAccount","").replace(/\n/g,""),
|
||||
gaDomain = $tw.wiki.getTiddlerText("$:/GoogleAnalyticsDomain","auto").replace(/\n/g,"");
|
||||
// Using ga "isogram" function
|
||||
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
|
||||
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
|
||||
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
|
||||
})(window,document,'script','https://www.google-analytics.com/analytics.js','ga');
|
||||
ga('create',gaAccount,gaDomain);
|
||||
ga('send','pageview');
|
||||
var gaMeasurementID = $tw.wiki.getTiddlerText("$:/GoogleAnalyticsMeasurementID","").replace(/\n/g,"");
|
||||
var url ="https://www.googletagmanager.com/gtag/js?id=" + gaMeasurementID;
|
||||
window.dataLayer = window.dataLayer || [];
|
||||
window.gtag = function() { window.dataLayer?.push(arguments); };
|
||||
window.gtag("js",new Date());
|
||||
window.gtag("config",gaMeasurementID);
|
||||
const scriptElement = window.document.createElement("script");
|
||||
scriptElement.async = true;
|
||||
scriptElement.src = url;
|
||||
window.document.head.appendChild(scriptElement);
|
||||
};
|
||||
// Initialise now if consent isn't required
|
||||
if($tw.wiki.getTiddlerText(CONFIG_CONSENT_REQUIRED_TITLE) !== "yes") {
|
||||
|
@ -1,6 +1,6 @@
|
||||
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.
|
||||
|
||||
|
@ -1,7 +1,6 @@
|
||||
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/
|
||||
# Click the ''Access Google Analytics'' button and follow instructions to set up your account
|
||||
# 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
|
||||
|
||||
@ -20,5 +20,5 @@ If you don't already have an account:
|
||||
|
||||
!! 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
|
||||
|
Loading…
Reference in New Issue
Block a user