本參考資料說明 Model
物件可用的方法。
方法摘要
方法 | |
---|---|
get(fieldName) |
傳回結果: 取得儲存在模型中的欄位值。 |
set(fieldName|fieldsObject, [fieldValue], [temporary]) |
傳回結果: 設定模型上的欄位/值組合或一組欄位/值組合。 |
方法說明
get
取得儲存在模型中的欄位值。
用量
model.get(fieldName);
參數
名稱 | 類型 | 必要 | 說明 |
---|---|---|---|
fieldName |
string |
是 | 要取得值的欄位名稱。 |
傳回
*
範例
ga('create', 'UA-XXXXX-Y', 'auto'); ga(function(tracker) { // Modifies sendHitTask to log the model's "hitPayload" field. tracker.set('sendHitTask', function(model) { var hitPayload = model.get('hitPayload'); console.log(hitPayload); }); }); ga('send', 'pageview');
set
設定模型上的欄位/值組合或一組欄位/值組合。
用量
// Sets a single field/value pair. model.set(fieldName, fieldValue, [temporary]);
// Sets a group of field/value pairs. model.set(fieldsObject, null, [temporary]);
參數
名稱 | 類型 | 必要 | 說明 |
---|---|---|---|
temporary |
boolean |
否 | 如果為 true ,這個值只會在模型上針對目前命中設定。 |
如需個別欄位說明文件,請參閱欄位參考資料。
傳回
undefined
範例
ga('create', 'UA-XXXXX-Y', 'auto'); ga(function(tracker) { // Grabs a reference to the default sendHitTask function. var originalSendHitTask = tracker.get('sendHitTask'); // Updates sendHitTask to obfuscate personally identifiable information (PII). tracker.set('sendHitTask', function(model) { var hitPayload = model.get('hitPayload') .replace(/%PII%/g, 'XXXXX'); // Updates the hitPayload string for the current hit. model.set('hitPayload', hitPayload, true); originalSendHitTask(model); }); }); ga('send', 'pageview');