Last active
June 10, 2024 17:39
-
-
Save sperand-io/edc31c93a6340f48fcf4 to your computer and use it in GitHub Desktop.
Revisions
-
sperand-io revised this gist
Jan 20, 2015 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -3,7 +3,7 @@ <head> <script type="text/javascript"> !function(){var analytics=window.analytics=window.analytics||[];if(analytics.invoked)window.console&&console.error&&console.error("Segment snippet included twice.");else{analytics.invoked=!0;analytics.methods=["trackSubmit","trackClick","trackLink","trackForm","pageview","identify","group","track","ready","alias","page","once","off","on"];analytics.factory=function(t){return function(){var e=Array.prototype.slice.call(arguments);e.unshift(t);analytics.push(e);return analytics}};for(var t=0;t<analytics.methods.length;t++){var e=analytics.methods[t];analytics[e]=analytics.factory(e)}analytics.load=function(t){var e=document.createElement("script");e.type="text/javascript";e.async=!0;e.src=("https:"===document.location.protocol?"https://":"http://")+"cdn.segment.com/analytics.js/v1/"+t+"/analytics.min.js";var n=document.getElementsByTagName("script")[0];n.parentNode.insertBefore(e,n)};analytics.SNIPPET_VERSION="3.0.0"; }}(); analytics.load('YOUR WRITE KEY'); </script> <script> // Forward all postMessage calls from the iframes that have data in the form {method:, arguments:} directly to Segment. -
sperand-io revised this gist
Jan 20, 2015 . 2 changed files with 2 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -19,7 +19,6 @@ var analyticsProxy = {}; // List of methods from the snippet at https://segment.com/docs/libraries/analytics.js/quickstart/ var methodsToProxy = [ 'trackSubmit', 'trackClick', @@ -34,8 +33,7 @@ 'page', 'once', 'off', 'on' ]; methodsToProxy.forEach(function(method) { analyticsProxy[method] = function( /* Variable arguments */ ) { This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -3,6 +3,7 @@ <head> <script type="text/javascript"> !function(){var analytics=window.analytics=window.analytics||[];if(analytics.invoked)window.console&&console.error&&console.error("Segment snippet included twice.");else{analytics.invoked=!0;analytics.methods=["trackSubmit","trackClick","trackLink","trackForm","pageview","identify","group","track","ready","alias","page","once","off","on"];analytics.factory=function(t){return function(){var e=Array.prototype.slice.call(arguments);e.unshift(t);analytics.push(e);return analytics}};for(var t=0;t<analytics.methods.length;t++){var e=analytics.methods[t];analytics[e]=analytics.factory(e)}analytics.load=function(t){var e=document.createElement("script");e.type="text/javascript";e.async=!0;e.src=("https:"===document.location.protocol?"https://":"http://")+"cdn.segment.com/analytics.js/v1/"+t+"/analytics.min.js";var n=document.getElementsByTagName("script")[0];n.parentNode.insertBefore(e,n)};analytics.SNIPPET_VERSION="3.0.0"; }}(); analytics.load(); </script> <script> // Forward all postMessage calls from the iframes that have data in the form {method:, arguments:} directly to Segment. -
sperand-io created this gist
Jan 20, 2015 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,49 @@ <script> /** * Provides a fake analytics object that sends all calls to the parent window for processing */ var analytics = (function() { var eventQueue = []; // Send the events to the frame if it's ready. function flush(method, args) { while (eventQueue.length) { var evt = eventQueue.shift(); parent.postMessage({ method: evt[0], arguments: evt[1] }, '*'); } } var analyticsProxy = {}; // List of methods from the snippet at https://segment.com/docs/libraries/analytics.js/quickstart/ // and also added 'load'. var methodsToProxy = [ 'trackSubmit', 'trackClick', 'trackLink', 'trackForm', 'pageview', 'identify', 'group', 'track', 'ready', 'alias', 'page', 'once', 'off', 'on', 'load' ]; methodsToProxy.forEach(function(method) { analyticsProxy[method] = function( /* Variable arguments */ ) { eventQueue.push([method, Array.prototype.slice(arguments)]); flush(); }; }); return analyticsProxy; })(); </script> This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,20 @@ <!doctype html> <html> <head> <script type="text/javascript"> !function(){var analytics=window.analytics=window.analytics||[];if(analytics.invoked)window.console&&console.error&&console.error("Segment snippet included twice.");else{analytics.invoked=!0;analytics.methods=["trackSubmit","trackClick","trackLink","trackForm","pageview","identify","group","track","ready","alias","page","once","off","on"];analytics.factory=function(t){return function(){var e=Array.prototype.slice.call(arguments);e.unshift(t);analytics.push(e);return analytics}};for(var t=0;t<analytics.methods.length;t++){var e=analytics.methods[t];analytics[e]=analytics.factory(e)}analytics.load=function(t){var e=document.createElement("script");e.type="text/javascript";e.async=!0;e.src=("https:"===document.location.protocol?"https://":"http://")+"cdn.segment.com/analytics.js/v1/"+t+"/analytics.min.js";var n=document.getElementsByTagName("script")[0];n.parentNode.insertBefore(e,n)};analytics.SNIPPET_VERSION="3.0.0"; }}(); </script> <script> // Forward all postMessage calls from the iframes that have data in the form {method:, arguments:} directly to Segment. window.onmessage = function(e){ var method = e.data.method; var args = e.data.arguments ? [].slice.call(e.data.arguments) : null; if (analytics[method]) { analytics[method].apply(analytics, args); } }; </script> </head> <body> </body> </html>