Skip to content

Instantly share code, notes, and snippets.

View jaredrileysmith's full-sized avatar

Jared R Smith jaredrileysmith

View GitHub Profile
@justusbluemer
justusbluemer / gtm-snippet-with-fallback.html
Created January 30, 2023 11:38
Google Tag Manager gtm.js 1st party snippet with www.googletagmanager.com fallback
<!-- Google Tag Manager -->
<script>
(function (w, d, s, l, i) {
w[l] = w[l] || [];
w[l].push({ "gtm.start": new Date().getTime(), event: "gtm.js" });
var f = d.getElementsByTagName(s)[0],
j = d.createElement(s),
dl = l != "dataLayer" ? "&l=" + l : "";
j.async = true;
j.onerror = function () {
// Call with decorateUrl('https://www.domain.com/url', 'UA-12345-1');
// Outputs the URL string with the Universal Analytics cross-domain linker in place.
// Tracking ID is optional. If you leave it out, the linker will be built
// with the settings of the first tracker found on the page.
function decorateUrl(urlString, trackingId) {
var ga = window[window['GoogleAnalyticsObject']];
if (ga && ga.getAll) {
var trackers = ga.getAll().filter(function(t) {
return trackingId ? t.get('trackingId') === trackingId : true;
});
<script async="async" src=//consent.trustarc.com/notice?domain=tibco.com&c=teconsent&js=nj&noticeType=bb&gtm=1 crossorigin=""></script>
<script>
window.trustArcCookieCounter = 0;
window.firedTrustArcConsent = false;
//look for the existence of the trust arc cookie that indicates if it's implied or expressed consent
function checkForTrustArcCookie() {
@shadybones
shadybones / CMAPI_Integration.js
Last active January 29, 2024 08:59
Partial integration between the TrustArc Consent Manager API and Google Tag Manager. This code allows for GTM event-based tag firing solution.
var __dispatched__ = {}; //Map of previously dispatched preference levels
/* First step is to register with the CM API to recieve callbacks when a preference update occurs
You must wait for the CM API (PrivacyManagerAPI object) to exist on the page before registering
*/
var __i__ = self.postMessage && setInterval(function(){
if(self.PrivacyManagerAPI && __i__){
var apiObject = { PrivacyManagerAPI:
{ action:"getConsentDecision",
timestamp: new Date().getTime(),
@joechristopher
joechristopher / GTM Backup Script for Google Sheets.js
Last active July 29, 2021 16:24
GTM Backup Script for Google Sheets
function getAccounts() {
var accountList = TagManager.Accounts.list();
for (var i = 0;i < accountList.account.length;i++) {
//if (accountList.account[i].accountId > 123456) { //if you reach a timeout, resume by manually updating this and re-running
getContainers(accountList.account[i].accountId,accountList.account[i].name);
Utilities.sleep(5000); //GTM only allows 25 queries per 100 seconds, so we have to slow it down
//}
}
}
@andrei-m
andrei-m / levenshtein.js
Last active October 9, 2024 10:36
Levenshtein distance between two given strings implemented in JavaScript and usable as a Node.js module
/*
Copyright (c) 2011 Andrei Mackenzie
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE