Open a URL using Google Apps Script without requiring additional user interaction.
Code also on StackOverflow.
<script>(function(){ | |
/* | |
This script is an alternative to the 'Add JavaScript API support to all YouTube videos' | |
setting in GTM's YT trigger. GTM's YT trigger will not load the YT API if no videos are | |
present at page load (it does add the enablejsapi param to dynanmically inserted videos, | |
but it will not load the YT API js). This script, on the other hand, should work in all cases. | |
*/ | |
if( window.YT ) return; | |
Open a URL using Google Apps Script without requiring additional user interaction.
Code also on StackOverflow.
(function(){ | |
var aI, pI, vI, a, p, v, rows = [], row; | |
for( aI = 0; aI<window.preload.accounts.length; aI++ ){ | |
row = []; | |
a = window.preload.accounts[aI]; | |
for( pI = 0; pI<a.wprops.length; pI++ ){ |
# Create an OAuth consumer with write access. | |
# For a callback URL, you can use: `https://www.google.com/` | |
# https://bitbucket.org/account/user/USERNAME/oauth-consumers/new | |
# Optional: Hardcode username, client key, and client secret into script. | |
# (but be aware of the danger of hardcoding credentials into any code!!) | |
# (if skipped, the script will securely prompt for info). | |
# Edit values | |
NEW_REPO_USER_OR_ORG="editme" |
;(function(window,undefined){ | |
/* | |
See LICENSE.txt file included in this distribution. | |
@version 0.2.0 | |
*/ | |
(function(k){function h(){g.debug&&k.console&&k.console.debug&&k.console.debug.apply(console,["%c[UniversalUtmz]","color:#ccc;border:1px solid #eee"].concat([].slice.call(arguments)))}function r(c,b){var a;if(!c||!b)return!c==!b;for(a in c)if(c.hasOwnProperty(a)&&(!b.hasOwnProperty(a)||c[a]!=b[a]))return!1;for(a in b)if(b.hasOwnProperty(a)&&(!c.hasOwnProperty(a)||c[a]!=b[a]))return!1;return!0}function t(){var c,b={},a,d=/(?:^|[^&]*&)([^=&]+)(?:=([^&]*))?/g;for(c=(c||k.location.search.substr(1)).split("+").join(" ");a= | |
d.exec(c);)b[decodeURIComponent(a[1])]=a[2]&&decodeURIComponent(a[2]);if(b.gclid)return{medium:"cpc",source:"google",campaign:"{adwords}",keyword:"{adwords}",content:"{adwords}",gclid:b.gclid};if(b.gclsrc)return{medium:"cpc",source:"google",campaign:"{DoubleClick}",keyword:"{DoubleClick}",content:"{DoubleClick}",gclsrc:b.gclsrc};if(b.utm_source)return h("Using data from UTM parameters."),m( |
Test
function getTLD(){ | |
var cookieName = '_tmp_detect_tld', | |
globalNamespacePageloadCache = cookieName; | |
return window[globalNamespacePageloadCache] || ( window[globalNamespacePageloadCache] = (function(){ | |
var i, domain, parts = location.hostname.split('.'), | |
UNDEFINED = '{{UNDEFINED}}', cKeyValPair, c; | |
if( window.navigator && navigator.cookieEnabled === false ){ return UNDEFINED+' cookies disabled'; } | |
for( i=parts.length-1; i>=0; i-- ){ | |
domain = parts.slice(i).join('.'); | |
cKeyValPair = cookieName+'_'+domain+'=1'; |
This code is for serving an AMP GTM container from your own domain, so that the GA Client ID can be shared between your AMP pages and the rest of your site (enabling them to be tracked together in the same GA property).
Once the endpoint is deployed, you'll need to replace //www.googletagmanager.com/amp.json
in the <amp-analytics>
embed with the path to your endpoint (leaving the query parameters in place) within your AMP template's source code:
<amp-analytics config="//www.googletagmanager.com/amp.json?id=GTM-XXXXX>m.url=SOURCE_URL" data-credentials="include"></amp-analytics>
You can specifiy the cookie domain by appending &cookieDomain=YOURDOMAIN.COM
to the endpoint URL.
<?php | |
// Callback for the GET request | |
function gtmAmpProxy_serve(){ | |
//error_reporting(0); | |
// Get the hostname of the request origin, and parse it for the pure domain name. | |
$domain = explode( ':', $_SERVER['HTTP_HOST'] )[0]; | |
if( !( $cookieDomain = @$_GET['cookieDomain'] ) ){ |
// Mirrors analytics.js logic to validate autolinker param, and returns cid if valid. | |
// Returns false if autolinker param found, but invalid. | |
// Otherwise returns undefined. | |
var getCidFromAutolinker = function(str) { | |
var joiner = function (cidGid, offset) { | |
var a = new Date, | |
b = window.navigator, | |
c = b.plugins || []; | |
var d = [cidGid, b.userAgent, a.getTimezoneOffset(), a.getYear(), a.getDate(), a.getHours(), a.getMinutes() + offset]; |