Hi all,
Has anyone managed to setup Google Analytics 4?
This should work. I've got the rest of it working too, but this bit should take of loading it.
$.ajax({ url: 'https://www.googletagmanager.com/gtag/js?id=YOURID', dataType: 'script', cache: true, }) window.dataLayer = window.dataLayer || []; function gtag(){dataLayer.push(arguments);} gtag('js', new Date()); gtag('config', 'YOURID');
Looking into it. But, w/o access to the of pages, it doesn't seem like an option. Am i wrong?
@martin_kabat
Did you find a way to use Google Analytics 4 in Canvas?
Regards
I have not. I tried using the Google provided tag inside our JS file, but that has not worked so I'm not sure what to do if we can't access the portion of the site where the tag needs to reside. I'd love it if somebody would be able to figure it out and comment here!
I believe the best solution for implementing Google Analytics 4 in Canvas is through the Google Tag Manager. Just follow the instructions provided by Christopher here: Using Google Tag Manager to add Google Analytics - Instructure Community (canvaslms.com)
You can also read the opening instructions provided in the earlier article that gave guidelines on how to implement Google Analytics: How to Set Up Google Analytics for Canvas (Archive... - Instructure Community (canvaslms.com)
Hello @martin_kabat, @dtod, et alia,
Below is our version which works perfectly, note the use of the UA tracking code, which works fine.
THese are the live feeds it produces with a single course added as a filter: https://lookerstudio.google.com/reporting/a1edcff7-926d-4810-8253-9ed15a3eaa23
I would now like to add all the other available dimensions https://portal.inshosteddata.com/docs and to publish the js file here for all to simply copy and paste (and sync in GA).
I'm going to have a go at it myself today but any guidance would be gratefully received.
Yours sincerely,
@JedKeenan
function g() {window.addEventListener("load", function () {ENV.current_user_roles.indexOf("teacher") >= 1 &&[...document.querySelectorAll(".teacher-only")].forEach((e) => {(function (e, o, t, a, n, s, r) {(e.GoogleAnalyticsObject = n),(e[n] =e[n] ||function () {(e[n].q = e[n].q || []).push(arguments);}),(e[n].l = 1 * new Date()),(s = o.createElement(t)),(r = o.getElementsByTagName(t)[0]),(s.async = 1),(s.src=a),r.parentNode.insertBefore(s, r);})(window, document, "script", "https://www.google-analytics.com/analytics.js", "gtag");function v(e) {try {localStorage.removeItem(e), localStorage.removeItem(e + "_expiresIn");} catch (o) {return console.log("removeStorage: Error removing key [" + e + "] from localStorage: " + JSON.stringify(o)), !1;}return !0;}function h(e) {var o = Date.now(),t = localStorage.getItem(e + "_expiresIn");if ((t == null && (t = 0), t < o)) return v(e), null;try {var a = localStorage.getItem(e);return a;} catch (n) {return console.log("getStorage: Error reading key [" + e + "] from localStorage: " + JSON.stringify(n)), null;}}function w(e, o, t) {t == null ? (t = 24 * 60 * 60) : (t = Math.abs(t));var a = Date.now(),n = a + t * 1e3;try {localStorage.setItem(e, o), localStorage.setItem(e + "_expiresIn", n);} catch (s) {return console.log("setStorage: Error setting key [" + e + "] in localStorage: " + JSON.stringify(s)), !1;}return !0;}async function _(e) {let t = await (await fetch("/api/v1/users/self/courses?per_page=100")).text();(t = t.replace("while(1);", "")), (t = JSON.parse(t));var a = JSON.stringify(t);w("ga_enrollments", a, null);var n = f(e, a);return n;}function f(e, o) {if (o != null) {let a = JSON.parse(o);for (var t = 0; t < a.length; t++) if (a[t].id == e) return a[t];}return null;}function u(e) {gtag("set", "dimension4", e.id),gtag("set", "dimension5", e.name),gtag("set", "dimension6", e.account_id),gtag("set", "dimension7", e.enrollment_term_id),gtag("set", "dimension8", e.enrollments[0].type),gtag("send", "pageview");}function m(e) {var o, t, a, n;if ((gtag("create", e, "auto"),(o = ENV.current_user_id),(t = ENV.current_user_roles),gtag("set", "userId", o),gtag("set", "dimension2", o),gtag("set", "dimension3", t),(n = window.location.pathname.match(/\/courses\/(\d+)/)),n)) {(n = n[1]), (a = 0);try {let r = h("ga_enrollments");if (r != null) {var s = f(n, r);s === null? _(n).then((l) => {l === null ? (gtag("set", "dimension4", n), gtag("send", "pageview")) : u(l);}): u(s);} else_(n).then((l) => {l === null ? (gtag("set", "dimension4", n), gtag("send", "pageview")) : u(l);});} catch {if (((a += 1), a > 5)) {gtag("set", "dimension4", n), gtag("send", "pageview");return;}}} else gtag("send", "pageview");}i();g();d();globalThis.DT_variables = c;m("UA-XXXXXXXXX-1");})();
Rendering bug here: Canvas - Instructure Community Seems to only appear in Edge; fine in Chrome and Firefox https://us.v-cdn.net/6038536/uploads/W3BKB9LY5FCV/recording-2026-04-08-144351.mp4
I have a developer key in our Test instance: How would I use this in a local program to make a REST API call? Looking at https://developerdocs.instructure.com/services/canvas/oauth2/file.developer_keys: Developer keys are OAuth2 client ID and secret pairs stored in Canvas that allow third-party applications to request…
I'm building a tool for my institution that imports grades from another LTI tool into Canvas so instructors can automate late assignment policies not otherwise supported by Canvas. I'm trying to use the LTIv1.3 ID which is readily available on the LTI-side as a link to the student record on Canvas, but I can't find the ID…
How can one track Canvas Media use without having the reports available from Canvas Studio? Checking API endpoints and the Data 2 schema, there do not seem to be dedicated Canvas Media endpoints. Am I missing some? A method I've considered is using the body field of the wiki_pages table, as this contains the html code of…
Hello, I'm trying to utilize an API call to pull completed certificates and was hoping to download and store the certs as a backup. I can successfully run the API call but it will not allow me to view the certificate unless I access the URL while signed into an account where it's "my" cert. Is there a permissions setting…