我正在努力让谷歌分析正确地报告使用Laravel Jetstream的InertiaJS堆栈。我需要跟踪单个页面的访问量,但由于它是一个SPA,我不确定该怎么做。我已经在我的app.blade中放置了标记,但它显示了所有流量,而不是特定于每个页面,也不能触发事件。
让GA进入Laravel Jetstream惯性堆栈的最好方法是什么?
发布于 2021-03-25 17:25:55
我选择使用惯性::share,然后在我的app.blade上,我引用了相应的元素,如标题等作为道具。
例如:RouteController (返回惯性视图):
Inertia::share([
'title' => $title,
'description' => $description,
'meta_image' => $meta_image,
'meta_url' => $meta_url
]);
return Inertia::render...App.blade:
<title>{{$page['props']['title'] ?? ''}}</title>
<meta name="description" content="{{$page['props']['description'] ?? ''}}">
...最后,在我的AppLayout.vue中,我有一个监视页面更改的道具:
watch: {
"$page.props.title"(newTitle) {
this.setPageData();
},
"$page.props.description"(newDescription) {
this.setPageData();
},
},只有真正需要观察标题,因为机器人应该加载每个页面新鲜(为了搜索引擎优化的目的),但这对于元标签(Open Graph)和GA跟踪每个页面都很好。
https://stackoverflow.com/questions/66435082
复制相似问题