Rails:在服务器/后端执行 Javascript(用于使用 Google Analytics 进行跟踪)? (无需浏览器)
好吧,我一直在努力解决这个问题......我做了大量的研究,但在谷歌上什么也没找到。
通常,要执行标准的谷歌分析,您只需在向用户显示的页面标题中转储一些 js 即可。没什么大不了的。
但是,我们正在通过 GA 获得越来越先进的跟踪,现在我们正准备使用他们最近的“电子商务”模块来跟踪我们的购买情况。因此,为了做到这一点,我们希望在确认并支付采购订单时运行一些额外的 JS 代码。
这听起来很简单,但问题是确认来自支付提供商通过通知系统(paypal 和 adyen,它们的工作原理基本相同)。他们所做的是将一些数据发布到网站上的表格中,并包含确认(或拒绝)信息,然后我们可以执行一些服务器端代码并验证或删除采购订单。
现在的问题是,此时如何执行 Google Analytics JS...因为这是我可以保证订单已完成且跟踪不会重复的唯一时间(对于转换而言,它是重要)如果用户刷新页面? 这里的问题是,当 paypal 发布到我们的表单时,我可以使用 GA JS 脚本生成响应,没有问题,但显然它永远不会被执行,因为它是服务器到服务器的连接,没有浏览器,没有 JS 引擎什么都没有......
任何我该如何解决这个问题,这真的很困扰我:(
谢谢,
亚历克斯
Ok, I have been struggling with this a lot... and I have done tons of research and found nothing on google.
Usually to perform the standard google analytics you just dump a little js in the header of the pages you display to your users. No big deal.
But, we are getting more and more advanced tracking with GA, and now we are at the point of tracking our purchases with their recent "eCommerce" module. So in order to do so we want to run some additional JS code when a purchase order has been confirmed and paid.
That sounds easy, but the issue is that the confirmation comes from the payment provider through a notification system (paypal and adyen, they basically work the same). What they do is that they post some data to a form on the site with the confirmation (or refusal) information et boom we can execute some server side code and validate or remove a purchase order.
The issue is now, how in h.ll do execute the Google Analytics JS at that point... because that's the only time when I can guarantee that the order has been fulfilled and that the tracking won't repeat itself (for conversion it's important) if the user refreshed the page ?
The issue here, is that when paypal post to our form, I can generate a response with the GA JS script no problem, but obviously it never gets executed as it's server to server connection, no browser, no JS engine nothing...
Any ideas how I could about this issue, it's really bugging me :(
Thanks,
Alex
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论