如果您对如何在React中使用GoogleAnalytics和分析?感兴趣,那么这篇文章一定是您不可错过的。我们将详细讲解如何在React中使用GoogleAnalytics的各种细节,并对分析?进行
如果您对如何在React中使用Google Analytics和分析?感兴趣,那么这篇文章一定是您不可错过的。我们将详细讲解如何在React中使用Google Analytics的各种细节,并对分析?进行深入的分析,此外还有关于Google Analytics(分析)API-如何创建新帐户、Google Analytics(分析)View ID问题、Google Analytics(分析)使用GTag,如何在JavaScript中为自定义细分添加代码?、Google Analytics(分析)如何查看所有用户的列表的实用技巧。
本文目录一览:- 如何在React中使用Google Analytics(分析)?(react开发chrome插件)
- Google Analytics(分析)API-如何创建新帐户
- Google Analytics(分析)View ID问题
- Google Analytics(分析)使用GTag,如何在JavaScript中为自定义细分添加代码?
- Google Analytics(分析)如何查看所有用户的列表
如何在React中使用Google Analytics(分析)?(react开发chrome插件)
在我的react
应用程序中,我有一些页面:
- 主要
- 服务
- 联系
- 个人资料(私人)
- 等等..
我需要跟踪用户使用Google Analytics(分析)的活动。我在react-ga上搜索了一下,一切都很好。但是,有了这个库,我必须在使用的每条路线上初始化我的GA。例如:
路线“ /”-主页:
class Main extends Component { componentDidMount() { initGA(); } render() { return ( <div> <Component1 /> <Component2 /> </div> ) }}
我的initGA()
样子是:
import ReactGA from ''react-ga'';export const initGA = () => { ReactGA.initialize(''UA-00000000-1''); ReactGA.pageview(window.location.pathname + window.location.search); console.log(window.location.pathname + window.location.search);}
我的App class
样子是:
class App extends Component { render() { return ( <BrowserRouter> <div className="App"> <Switch> <Route exact path="/" component={Main} /> <Route exact path="/signup" component={SignupLayout} /> <Route component={PublicLayout} /> </Switch> </div> </BrowserRouter> ); }}
在使用方式上,react-ga
我initGA()
在每个组件上添加了功能,这些功能会在路线响应中呈现。我认为initGA()
在每个组件中重复都是不正确的。拜托,伙计们,您如何使用react-ga
?什么是使用react-ga的正确方法?
答案1
小编典典要使其工作,需要使用Router
功能。因此在App组件中import { Router } from ''react-router-dom''
。它必须是路由器而不是BrowserRouter。
然后 import createHistory from ''history/createBrowserHistory''
const history = createHistory()ReactGA.initialize(''UA-000000-1'');history.listen((location, action) => { ReactGA.pageview(location.pathname + location.search); console.log(location.pathname)});
此代码将在每次更改路线时触发!
比给路由器组件一个历史属性。
完整的代码:
import React, { Component } from ''react'';import { Router, Route, Switch } from ''react-router-dom'';import createHistory from ''history/createBrowserHistory''import Main from ''./components/pages/Main'';import ReactGA from ''react-ga'';const history = createHistory()ReactGA.initialize(''UA-00000000-1'');history.listen((location, action) => { ReactGA.pageview(location.pathname + location.search); console.log(location.pathname)});class App extends Component { render() { return ( <Router history={history}> <div className="App"> <Switch> <Route exact path="/" component={Main} /> <Route exact path="/signup" component={SignupLayout} /> <Route component={PublicLayout} /> </Switch> </div> </Router> ); }}export default App;
Google Analytics(分析)API-如何创建新帐户
您无法做到。管理API仅允许对帐户https://developers.google.com/analytics/devguides/config/mgmt/v3/account-management#account_summaries
进行列表操作唯一的解决方案是使用Provisioning API。它可用于创建新的Google Analytics(分析)帐户,并为您的客户大规模启用Google Analytics(分析):https://developers.google.com/analytics/devguides/config/provisioning/v3/
无论如何,Provisioning API当前仅可通过邀请使用。
Google Analytics(分析)View ID问题
如何解决Google Analytics(分析)View ID问题?
我想使用API获取Mobile App Google Analytics(分析)报告。我浏览了google文档,发现了getReport()函数来获取报告,但是不幸的是我们需要View id来获取结果。 Mobile App谷歌分析仪表板不支持或不显示视图ID。有人可以在不使用视图ID的情况下帮助我获取移动应用Google Analytics(分析)的报告吗?
或者帮助我,如果我们还有其他方法可以实现这一目标。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)
Google Analytics(分析)使用GTag,如何在JavaScript中为自定义细分添加代码?
该文档页面描述了如何将自定义维度和指标发送到Google Analytics(分析)。在某些情况下,这是您发送给GA的值。您必须在GA(https://support.google.com/analytics/answer/2709829?hl=en)的管理属性中设置此“变量”,因此您可以在此处定义名称和范围(在您的情况下为Session),并将数据从网站发送到自定义“变量”的索引'和综合浏览量或事件。
细分是Google Analytics(分析)数据的子集,您可以在GA界面中对其进行配置(即,具有自定义维度并具有您偏爱的值的会话),并将其应用于报告中,以仅查看基于该子集的过滤数据。 / p>
[编辑]
您不必使用自定义变量,而是使用您创建的自定义维度的名称。此外,您的gtag代码不包含将自定义维度发送到Google Analytics(分析)的部分,您必须遵循指向您所放置文档的链接。
您的疑问是,为什么要使用不再存在的自定义变量,因此在创建细分后,请使用自定义维度名称相应地修改细分。
Google Analytics(分析)如何查看所有用户的列表
如果您已经在使用Google Analtyics API来获取报告,为什么不使用Management APi来获取用户有权访问的所有帐户的列表
Account summeries.list将为您提供。
我不是Java开发人员,但是代码应该是这样的。
function queryAccounts() {
// Load the Google Analytics client library.
gapi.client.load('analytics','v3').then(function() {
// Get a list of all Google Analytics accounts for this user
gapi.client.analytics.management.accountSummaries.list().then(handleAccounts);
});
}
从Hello Analytics API: JavaScript quickstart for web applications中无耻地撕掉了代码,并通过疯狂的猜测对其进行了一些改动。
关于如何在React中使用Google Analytics和分析?的介绍现已完结,谢谢您的耐心阅读,如果想了解更多关于Google Analytics(分析)API-如何创建新帐户、Google Analytics(分析)View ID问题、Google Analytics(分析)使用GTag,如何在JavaScript中为自定义细分添加代码?、Google Analytics(分析)如何查看所有用户的列表的相关知识,请在本站寻找。
本文标签: