analytics correction to run through segment, clean up extra methods in config.rb (#5562)

This commit is contained in:
Jeff Escalante 2018-10-19 17:04:09 -04:00 committed by Mitchell Hashimoto
parent c1d435c80c
commit 2503568f3c
2 changed files with 13 additions and 63 deletions

View file

@ -13,31 +13,19 @@ activate :hashicorp do |h|
h.datocms_api_key = '78d2968c99a076419fbb'
end
# ready do
# dato.tap do |dato|
# sitemap.resources.each do |page|
# if page.path.match(/\.html$/)
# if page.metadata[:options][:layout] && ['docs', 'guides', 'api', 'intro'].include?(page.metadata[:options][:layout])
# # get the page category from the url
# match = page.path.match(/^(.*?)\//)
# # proxy the page route
# proxy "#{page.path}", "/content", {
# layout: page.metadata[:options][:layout],
# locals: page.metadata[:page].merge({
# content: render(page),
# sidebar_data: get_sidebar_data(match ? match[1] : nil)
# })
# }, ignore: true
# end
# end
# end
# end
# end
# Netlify redirects/headers
proxy '_redirects', 'netlify-redirects', ignore: true
helpers do
# get correct analytics id
def segmentId()
if (ENV['ENV'] == 'production')
'OdSFDq9PfujQpmkZf03dFpcUlywme4sC'
else
'0EXTgkNx0Ydje2PGXVbRhpKKoe5wtzcE'
end
end
# Formats and filters a category of docs for the sidebar component
def get_sidebar_data(category)
sitemap.resources.select { |resource|
@ -139,42 +127,3 @@ helpers do
return classes.join(" ")
end
end
# custom version of middleman's render that renders only a file's contents
# without front matter or layouts
def render(page)
full_path = page.file_descriptor[:full_path]
relative_path = page.file_descriptor[:relative_path]
content = File.read(full_path).to_s
locals = {}
options = {}
data = @app.extensions[:front_matter].data(relative_path.to_s)
frontmatter = data[0]
content = data[1]
context = @app.template_context_class.new(@app, locals, options)
_render_with_all_renderers(relative_path.to_s, locals, context, options)
end
# pirated from middleman source, its protected there sadly
def _render_with_all_renderers(path, locs, context, opts, &block)
# Keep rendering template until we've used up all extensions. This
# handles cases like `style.css.sass.erb`
content = nil
while ::Middleman::Util.tilt_class(path)
begin
opts[:template_body] = content if content
content_renderer = ::Middleman::FileRenderer.new(@app, path)
content = content_renderer.render(locs, opts, context, &block)
path = path.sub(/\.[^.]*\z/, '')
rescue LocalJumpError
raise "Tried to render a layout (calls yield) at #{path} like it was a template. Non-default layouts need to be in #{@app.config[:source]}/#{@app.config[:layouts_dir]}."
end
end
content
end

View file

@ -33,9 +33,10 @@
<link rel='stylesheet' href='/css/index.css' />
<!--[if lt IE 9]>
<%= javascript_include_tag "ie-compat" %>
<![endif]-->
<!-- Analytics scrpts -->
<script defer>
!function(){var e=window.analytics=window.analytics||[];if(!e.initialize)if(e.invoked)window.console&&console.error&&console.error("Segment snippet included twice.");else{e.invoked=!0,e.methods=["trackSubmit","trackClick","trackLink","trackForm","pageview","identify","reset","group","track","ready","alias","debug","page","once","off","on"],e.factory=function(t){return function(){var a=Array.prototype.slice.call(arguments);return a.unshift(t),e.push(a),e}};for(var t=0;t<e.methods.length;t++){var a=e.methods[t];e[a]=e.factory(a)}e.load=function(e){var t=document.createElement("script");t.type="text/javascript",t.async=!0,t.src=("https:"===document.location.protocol?"https://":"http://")+"cdn.segment.com/analytics.js/v1/"+e+"/analytics.min.js";var a=document.getElementsByTagName("script")[0];a.parentNode.insertBefore(t,a)},e.SNIPPET_VERSION="4.0.0",e.load("<%= segmentId %>")}}();var om597a24292a958,om597a24292a958_poll=function(){var e=0;return function(t,a){clearInterval(e),e=setInterval(t,a)}}();!function(e,t,a){if(e.getElementById(a))om597a24292a958_poll(function(){if(window.om_loaded&&!om597a24292a958)return(om597a24292a958=new OptinMonsterApp).init({s:"35109.597a24292a958",staging:0,dev:0,beta:0})},25);else{var n=!1,o=e.createElement("script");o.id=a,o.src="//a.optnmstr.com/app/js/api.min.js",o.async=!0,o.onload=o.onreadystatechange=function(){if(!(n||this.readyState&&"loaded"!==this.readyState&&"complete"!==this.readyState))try{n=om_loaded=!0,(om597a24292a958=new OptinMonsterApp).init({s:"35109.597a24292a958",staging:0,dev:0,beta:0}),o.onload=o.onreadystatechange=null}catch(e){}},(document.getElementsByTagName("head")[0]||document.documentElement).appendChild(o)}}(document,0,"omapi-script");analytics.page()
</script>
<%= yield_content :head %>
</head>