使用不同的跟踪对象管理多个实施

如果您实例化多个跟踪对象,则可以向不同的报表包发送不同的数据。这两个跟踪对象会相互独立地运作。

// Instantiate two separate tracking objects to two different report suites
var s = s_gi('examplersid1');
var z = s_gi('examplersid2');

// The s object and z object contain their own independent Analytics variables simultaneously
s.pageName = "Example page name 1";
z.pageName = "Example page name 2";

// Send data to the examplersid1 report suite
s.t();

// Send data to the examplersid2 report suite
z.t();

覆盖 s 对象后还原 AppMeasurement 变量

某些第三方工具可能还使用 JavaScript s 对象。如果意外覆盖了网站上的 s 对象,可以使用相同的 RSID 字符串参数调用 s_gi 以恢复所有被覆盖的变量和方法。

// Step 1: Instantiate the tracking object
var s = s_gi("examplersid");

// Step 2: Set eVar1
s.eVar1 = "Example value";

// Step 3: Accidentally overwrite the tracking object
s = "3rd party tool";

// Step 4: If you attempt to send a tracking call, an error is returned. Instead, re-instantiate the tracking object
s = s_gi("examplersid");

// Step 5: The previous values of all variables are preserved. You can send a tracking call and eVar1 is correctly set
s.t();

使用多个变量引用同一跟踪对象

如果两个变量使用同一报表包引用同一 s_gi() 函数,则可以交替使用这些变量。

// If the RSID is the same, any variables set in the 's' tracking object also get set in 'z' tracking object
var s = s_gi('examplersid');
var z = s_gi('examplersid');

s.eVar1 = "Shared tracking object value";

// This tracking call contains the above eVar1 value
z.t();
上一页函数概述

Analytics