我正在尝试获得一个主页,该主页在 Isotope 下包含大量内容
在 Google Analytics 中将每个哈希更改显示为一次综合浏览量。本来,我打算把它作为事件来做,但它真的应该是综合浏览量。
所以我设置了修改后的 GA:
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-XXXXXXXX-X', {'allowAnchor': true});
ga('send', 'pageview', { 'page': location.pathname + location.search + location.hash});
在 Google Analytics 中,如果有人转到特定 URL,我现在会看到哈希标签 — 例如:http://www.example.com/#pet-health 如果他们重新加载页面,我会在 GA 中看到该哈希值,但如果他们单击同位素“导航”链接来访问它,则看不到。如果他们点击,我只会看到“/”
在同位素发射中,我所拥有的似乎不起作用:
//Sets up filtering on click of Isotope navigational elements
$('#isotopeFilters a, .subnav a, #isotopeContainer .isotopeNav a, .page-template-page-home-php #logo').click(function(){
var selector = $(this).attr('data-filter');
var prettyselector = selector.substr(1);
ga('send', 'pageview', location.pathname+location.search+location.hash);
location.hash = prettyselector;
$('#isotopeFilters a, .subnav a').removeClass('active');
$('a[class="' + prettyselector + '"]').addClass('active');
$container.isotope({
filter: selector,
itemSelector: '.item',
masonry: {
columnWidth: 270
},
animationOptions: {
duration: 750,
easing: 'linear',
queue: false,
}
});
return false;
});
我认为点击函数中的这一行可以解决问题:
ga('send', 'pageview', location.pathname+location.search+location.hash);
是我的语法不正确还是遗漏了什么?
//Fires Isotope functionality when hash/URL changes
$(window).hashchange( function(){
if(location.hash!=''){
var hashfilter = '.' + location.hash.substr(1);
}else{
var hashfilter = '.home';
}
$container.isotope({
filter: hashfilter,
itemSelector: '.item',
masonry: {
columnWidth: 270
},
animationOptions: {
duration: 750,
easing: 'linear',
queue: false,
}
});
isotopeSubNav();
});
if(location.hash!=''){
var hashfilter = '.' + location.hash.substr(1);
ga('send', 'pageview', location.pathname+location.search+location.hash);
$(hashfilter).addClass('active');
}
那是使用相同的语法,所以我假设如果我修复了一个语法,将语法复制到 hashchange 函数也将获得该记录。
最佳答案
要更改发送到 GA 的页面路径,您只需对代码稍作修改:
ga('send', 'pageview', {'page': location.pathname+location.search+location.hash});
可在此处找到更多信息:https://developers.google.com/analytics/devguides/collection/analyticsjs/advanced?hl=en#fieldObject
关于javascript - Google Analytics 在哈希变化时设置页面 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32378607/
我有一个Ruby程序,它使用rubyzip压缩XML文件的目录树。gem。我的问题是文件开始变得很重,我想提高压缩级别,因为压缩时间不是问题。我在rubyzipdocumentation中找不到一种为创建的ZIP文件指定压缩级别的方法。有人知道如何更改此设置吗?是否有另一个允许指定压缩级别的Ruby库? 最佳答案 这是我通过查看rubyzip内部创建的代码。level=Zlib::BEST_COMPRESSIONZip::ZipOutputStream.open(zip_file)do|zip|Dir.glob("**/*")d
我在使用omniauth/openid时遇到了一些麻烦。在尝试进行身份验证时,我在日志中发现了这一点:OpenID::FetchingError:Errorfetchinghttps://www.google.com/accounts/o8/.well-known/host-meta?hd=profiles.google.com%2Fmy_username:undefinedmethod`io'fornil:NilClass重要的是undefinedmethodio'fornil:NilClass来自openid/fetchers.rb,在下面的代码片段中:moduleNetclass
我需要从一个View访问多个模型。以前,我的links_controller仅用于提供以不同方式排序的链接资源。现在我想包括一个部分(我假设)显示按分数排序的顶级用户(@users=User.all.sort_by(&:score))我知道我可以将此代码插入每个链接操作并从View访问它,但这似乎不是“ruby方式”,我将需要在不久的将来访问更多模型。这可能会变得很脏,是否有针对这种情况的任何技术?注意事项:我认为我的应用程序正朝着单一格式和动态页面内容的方向发展,本质上是一个典型的网络应用程序。我知道before_filter但考虑到我希望应用程序进入的方向,这似乎很麻烦。最终从任何
我想要做的是有2个不同的Controller,client和test_client。客户端Controller已经构建,我想创建一个test_clientController,我可以使用它来玩弄客户端的UI并根据需要进行调整。我主要是想绕过我在客户端中内置的验证及其对加载数据的管理Controller的依赖。所以我希望test_clientController加载示例数据集,然后呈现客户端Controller的索引View,以便我可以调整客户端UI。就是这样。我在test_clients索引方法中试过这个:classTestClientdefindexrender:template=>
我正在查看instance_variable_set的文档并看到给出的示例代码是这样做的:obj.instance_variable_set(:@instnc_var,"valuefortheinstancevariable")然后允许您在类的任何实例方法中以@instnc_var的形式访问该变量。我想知道为什么在@instnc_var之前需要一个冒号:。冒号有什么作用? 最佳答案 我的第一直觉是告诉你不要使用instance_variable_set除非你真的知道你用它做什么。它本质上是一种元编程工具或绕过实例变量可见性的黑客攻击
我想设置一个默认日期,例如实际日期,我该如何设置?还有如何在组合框中设置默认值顺便问一下,date_field_tag和date_field之间有什么区别? 最佳答案 试试这个:将默认日期作为第二个参数传递。youcorrectlysetthedefaultvalueofcomboboxasshowninyourquestion. 关于ruby-on-rails-date_field_tag,如何设置默认日期?[rails上的ruby],我们在StackOverflow上找到一个类似的问
我是一个Rails初学者,但我想从我的RailsView(html.haml文件)中查看Ruby变量的内容。我试图在ruby中打印出变量(认为它会在终端中出现),但没有得到任何结果。有什么建议吗?我知道Rails调试器,但更喜欢使用inspect来打印我的变量。 最佳答案 您可以在View中使用puts方法将信息输出到服务器控制台。您应该能够在View中的任何位置使用Haml执行以下操作:-puts@my_variable.inspect 关于ruby-on-rails-如何在我的R
我有一个这样的哈希数组:[{:foo=>2,:date=>Sat,01Sep2014},{:foo2=>2,:date=>Sat,02Sep2014},{:foo3=>3,:date=>Sat,01Sep2014},{:foo4=>4,:date=>Sat,03Sep2014},{:foo5=>5,:date=>Sat,02Sep2014}]如果:date相同,我想合并哈希值。我对上面数组的期望是:[{:foo=>2,:foo3=>3,:date=>Sat,01Sep2014},{:foo2=>2,:foo5=>5:date=>Sat,02Sep2014},{:foo4=>4,:dat
我是rails的新手,想在form字段上应用验证。myviewsnew.html.erb.....模拟.rbclassSimulation{:in=>1..25,:message=>'Therowmustbebetween1and25'}end模拟Controller.rbclassSimulationsController我想检查模型类中row字段的整数范围,如果不在范围内则返回错误信息。我可以检查上面代码的范围,但无法返回错误消息提前致谢 最佳答案 关键是您使用的是模型表单,一种显示ActiveRecord模型实例属性的表单。c
我使用Ember作为我的前端和GrapeAPI来为我的API提供服务。前端发送类似:{"service"=>{"name"=>"Name","duration"=>"30","user"=>nil,"organization"=>"org","category"=>nil,"description"=>"description","disabled"=>true,"color"=>nil,"availabilities"=>[{"day"=>"Saturday","enabled"=>false,"timeSlots"=>[{"startAt"=>"09:00AM","endAt"=>