Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
drupal/metatag_segment / js / segment.js
Size: Mime:
/**
 * Taken from https://segment.com/docs/sources/website/analytics.js/quickstart/
 * and customized.
 */
!function(drupalSettings){var analytics=window.analytics=window.analytics||[];if(!analytics.initialize)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","reset","group","track","ready","alias","debug","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,e){var n=document.createElement("script");n.type="text/javascript";n.async=!0;n.src="https://cdn.segment.com/analytics.js/v1/"+t+"/analytics.min.js";var a=document.getElementsByTagName("script")[0];a.parentNode.insertBefore(n,a);analytics._loadOptions=e};analytics.SNIPPET_VERSION="4.1.0";

  var defaultKey  = drupalSettings.metatag_segment.default_write_key;
  var writeKeyTag = document.querySelector('meta[name="segment:write:key"]');
  var pageNameTag = document.querySelector('meta[name="segment:page:name"]');
  var key         = writeKeyTag ? writeKeyTag.getAttribute('content') : defaultKey;

  if(key) {
    analytics.load(key);

    if(pageNameTag) {
      analytics.page(pageNameTag.getAttribute('content'));
    }
  }

}}(drupalSettings);