Model Object Reference

This reference describes the methods available on the Model object.

Method Summary

Methods
get(fieldName)

returns: *

Gets the value of a field stored on the model.

set(fieldName|fieldsObject, [fieldValue], [temporary])

returns: undefined

Sets a field/value pair or a group of field/value pairs on the model.

Method Details

get

Gets the value of a field stored on the model.

Usage

model.get(fieldName);

Parameters

Name Type Required Description
fieldName string yes The name of the field the get the value of.

Returns

*

Example

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 field/value pair or a group of field/value pairs on the model.

Usage

// Sets a single field/value pair.
model.set(fieldName, fieldValue, [temporary]);
// Sets a group of field/value pairs.
model.set(fieldsObject, null, [temporary]);

Parameters

Name Type Required Description
temporary boolean no If true the value is only set on the model for the current hit.

See the field reference for individual field documentation.

Returns

undefined

Example

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');