如何把GA的网站热力图统计追踪配置接入到网站里呢?

  • Post author:
  • Post category:其他


要将谷歌热力图代码添加到WordPress网站后台,可以按照以下步骤操作:



谷歌

地图热力图的官方网站上创建一个账户并生成 API 密钥。

在WordPress网站的后台找到主题编辑器(Appearance > Editor)。

找到您正在使用的主题的 functions.php 文件,并将以下代码添加到文件底部:

php

Copy code

function add_google_heatmap() {

wp_enqueue_script( ‘google-maps’, ‘https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY’ );

wp_enqueue_script( ‘google-heatmap’, ‘https://www.gstatic.com/charts/loader.js’ );

}

add_action( ‘wp_enqueue_scripts’, ‘add_google_heatmap’ );

确保将 YOUR_API_KEY 替换为您在第一步中生成的 API 密钥。

在 WordPress 后台中创建一个新的页面或文章,并将以下代码添加到页面或文章中:

html

Copy code

<div id=”map”></div>

将以下 JavaScript 代码添加到页面或文章的底部:

javascript

Copy code

google.charts.load(‘current’, {

‘packages’:[‘heatmap’],

‘mapsApiKey’: ‘YOUR_API_KEY’

});

google.charts.setOnLoadCallback(drawHeatmap);

function drawHeatmap() {

var data = google.visualization.arrayToDataTable([

[‘Latitude’, ‘Longitude’, ‘Density’],

[37.782, -122.447, 0.5],

[37.782, -122.445, 1],

[37.782, -122.443, 2],

[37.782, -122.441, 3],

[37.782, -122.439, 2],

[37.782, -122.437, 0.5],

[37.782, -122.435, 0.5],

[37.785, -122.447, 1],

[37.785, -122.445, 1],

[37.785, -122.443, 1],

[37.785, -122.441, 2],

[37.785, -122.439, 3],

[37.785, -122.437, 4],

[37.785, -122.435, 2],

[37.789, -122.447, 2],

[37.789, -122.445, 3],

[37.789, -122.443, 4],

[37.789, -122.441, 5],

[37.789, -122.439, 7],

[37.789, -122.437, 8],

[37.789, -122.435, 9],

[37.793, -122.447, 10],

[37.793, -122.445, 9],

[37.793, -122.443, 8],

[37.793, -122.441, 7],

[37.793, -122.439, 6],

[37.793, -122.437, 5],

[37.793, -122.435, 4]

]);

var options = {

mapType: ‘styledMap’,

maxIntensity: 10,

radius: 20,

gradient: {

0.4:

要将谷歌热力图代码添加到WordPress网站后台,可以按照以下步骤操作:

在谷歌地图热力图的官方网站上创建一个账户并生成 API 密钥。

在WordPress网站的后台找到主题编辑器(Appearance > Editor)。

找到您正在使用的主题的 functions.php 文件,并将以下代码添加到文件底部:

php

Copy code

function add_google_heatmap() {

wp_enqueue_script( ‘google-maps’, ‘https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY’ );

wp_enqueue_script( ‘google-heatmap’, ‘https://www.gstatic.com/charts/loader.js’ );

}

add_action( ‘wp_enqueue_scripts’, ‘add_google_heatmap’ );

确保将 YOUR_API_KEY 替换为您在第一步中生成的 API 密钥。

在 WordPress 后台中创建一个新的页面或文章,并将以下代码添加到页面或文章中:

html

Copy code

<div id=”map”></div>

将以下 JavaScript 代码添加到页面或文章的底部:

javascript

Copy code

google.charts.load(‘current’, {

‘packages’:[‘heatmap’],

‘mapsApiKey’: ‘YOUR_API_KEY’

});

google.charts.setOnLoadCallback(drawHeatmap);

function drawHeatmap() {

var data = google.visualization.arrayToDataTable([

[‘Latitude’, ‘Longitude’, ‘Density’],

[37.782, -122.447, 0.5],

[37.782, -122.445, 1],

[37.782, -122.443, 2],

[37.782, -122.441, 3],

[37.782, -122.439, 2],

[37.782, -122.437, 0.5],

[37.782, -122.435, 0.5],

[37.785, -122.447, 1],

[37.785, -122.445, 1],

[37.785, -122.443, 1],

[37.785, -122.441, 2],

[37.785, -122.439, 3],

[37.785, -122.437, 4],

[37.785, -122.435, 2],

[37.789, -122.447, 2],

[37.789, -122.445, 3],

[37.789, -122.443, 4],

[37.789, -122.441, 5],

[37.789, -122.439, 7],

[37.789, -122.437, 8],

[37.789, -122.435, 9],

[37.793, -122.447, 10],

[37.793, -122.445, 9],

[37.793, -122.443, 8],

[37.793, -122.441, 7],

[37.793, -122.439, 6],

[37.793, -122.437, 5],

[37.793, -122.435, 4]

]);

var options = {

mapType: ‘styledMap’,

maxIntensity: 10,

radius: 20,

gradient: {

0.4:

配置以后,就可以在谷歌分析里分析用户行为了。



版权声明:本文为2301_76418831原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。