如何将Universal Analytics集成到Chrome扩展中? [英] How do you integrate Universal Analytics in to Chrome Extensions?

查看:103
本文介绍了如何将Universal Analytics集成到Chrome扩展中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Chrome扩展指南中包含旧分析安装教程: https://developer.chrome.com/extensions/ tut_analytics.html

The chrome extension guide has a tutorial for the old analytics install: https://developer.chrome.com/extensions/tut_analytics.html

这些说明只是说要链接到https版本并更新清单以允许从该URL加载脚本。所以这些应该仍然适用于新版本。事实上,我可以看到从服务器加载脚本。

The instructions just say to link to the https version and update the manifest to allow loading scripts from that URL. So those should still apply to the new version. And in fact I can see the script loading from the server.

一旦脚本加载分析没有正确初始化它自己,并且从不处理它的内部队列(ga.f)将这些事件发送到服务器。控制台中没有错误。这只是安静地没有做任何事。

Once the script loads analytics does not properly initialize it self and never processes it's internal queue (ga.f) to send those events to the server. There is no error in the console. It's just quietly does nothing.

我的猜测是,新的Universal Analytics只是没有设置在扩展环境中运行,但通用文档没有提到: https://developers.google.com/analytics/devguides/collection/analyticsjs/

My guess is that the new Universal Analytics is just not set up to run in the the extension environment but the universal docs make no mention of that: https://developers.google.com/analytics/devguides/collection/analyticsjs/

没有人知道是否有可能将Universal Analytics添加到扩展程序,以及何时可以添加它?

does anyone know if it's even possible to add Universal Analytics to an extension yet and when that might be added?

推荐答案

问题

There's an issue for that on Google code: The solution is to pass analytics your own protocol check function or simply null for no checking, in an official way.

这个必须在之后 em> ga('create',...)

This has to come after ga('create', ...) :

ga('set', 'checkProtocolTask', null); // Disable file protocol checking.

因此,您无需修改​​原始analytics.js脚本。只需添加标准的跟踪代码片段(不要忘记添加https:前缀)并添加 https:// www.google-analytics.com 至您的内容安全政策。

So you don't need to modify the original analytics.js script. Just include the standard tracking code snippet (dont' forget to add the "https:" prefix) and add "https://www.google-analytics.com" to your Content Security Policy.

ayal gelles解决方案的说明:
无需因为它已包含在'self'中,所以将 chrome-extension:// ... 添加到内容安全策略中。声明。此外,不应通过硬编码URL加载脚本,而应使用 chrome.runtime.getURL(path / to / analytics.js)。这样您就不需要知道您的分机号,Chrome会为您填写。

A note to ayal gelles' solution: It is not necessary to add chrome-extension://... to the Content Security Policy since it's already included in the 'self' statement. Also, instead of loading the script via hardcoded URL you should use chrome.runtime.getURL("path/to/analytics.js"). This way you don't need to know your extension's ID, Chrome will fill it in for you.

这篇关于如何将Universal Analytics集成到Chrome扩展中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆