Upsight logo Back to top

Method Reference

extendSession

Description


Extends the current session by an amount equal to the configured sessionLength value

extendSession

Example


upsight.extendSession();

getAllAttributes

Description


Gets all of the user attributes

getAllAttributes

Example


upsight.getAllAttributes(); //=> {'foo': 'bar', 'baz': '23'}

getAttribute

Description


Gets an attribute

getAttribute

Parameters


NameTypeDescription
attrstringThe user attribute to be retrieved.

getAttribute

Example


// All stored attributes are cast as strings
upsight.getAttribute('foo'); // => 'bar'
upsight.getAttribute('baz'); // => '23'

getSenderId

Description


Gets the auto-generated sid

getSenderId

Example


//Asynchronously get the senderId.
upsight.getSenderId(function(senderId) {
  console.log(senderId);  // Logs the sender ID
});

//Synchronously gets the senderId.  This may return null if called quickly after initialization.
upsight.getSenderId();

init

Description


Initialize the SDK

init

Parameters


NameTypeDescription
tokenstringThe token of the application being instrumented
optionsobjectConfiguration options to override
Properties
NameTypeAttributesDefaultDescription
logLevelstring <optional>
Specifies the minimum logging level outputted by the sdk. Leave blank to disable logging. One of: debug, info, warn, exception
useLocalboolean <optional>
false Specifies whether sdk should use localStorage vs. cookie storage
sessionLengthint <optional>
1800 The duration (in seconds) of a session
appVersionstring <optional>

init

Example


upsight.init('apptoken9933', {
  useLocal: true
});

removeAllAttributes

Description


Removes all of the user attributes

removeAllAttributes

Example


upsight.removeAllAttributes();

removeAttribute

Description


Removes an attribute

removeAttribute

Parameters


NameTypeDescription
attrstringThe user attribute to be removed.

removeAttribute

Example


upsight.removeAttribute('bar');

setAttribute

Description


Sets an attribute. All attribute values are cast to strings.

setAttribute

Parameters


NameTypeDescription
attrstring | objectThe user attribute to be set. This param can be a string name to represent the key for the attribute, or an object that contains multiple attributes to be set.
valueobjectAny type of value to be set for the attribute. This param is necessary only if the attr type is a string. If omitted, the value will default to an empty string.

setAttribute

Example


upsight.setAttribute('foo', 'bar');
upsight.setAttribute('baz', 23);
upsight.setAttribute({hi: 'there', good: 'bye'});

startNewSession

Description


Stars a new session

startNewSession

Example


upsight.startNewSession();

trackCustomEvent

Description


Tracks a custom event

trackCustomEvent

Parameters


NameTypeDescription
typestringThe type of the custom event. Value cannot be an empty string
eventDataobjectThe event data to be sent for the custom event.

trackCustomEvent

Example


upsight.trackCustomEvent('joined_group', {
  group_name: 'surfers',
  group_status: 'premium'
});

trackMonetizationPriceQuantity

Description


Tracks a monetization event using price and quantity

trackMonetizationPriceQuantity

Parameters


NameTypeDescription
priceintThe price of the product
quantityintThe quantity of the product
currencystringThe currency
upsightDataobjectThe optional data to be set for monetization
Properties
NameTypeAttributesDescription
productstring<optional>
The name of the product
resolutionstring<optional>
The resolution of the purchase.One of: buy, cancel, fraud, or refund
eventDataobjectAny custom event data to be sent

trackMonetizationPriceQuantity

Example


upsight.trackMonetizationPriceQuantity(20, 3, 'usd', {
  product: 'super-swipe',
  resolution: 'buy'
}, {
  purchased_from: 'cart'

trackMonetizationTotal

Description


Tracks a monetization event using total price

trackMonetizationTotal

Parameters


NameTypeDescription
totalPriceintThe total price of the product
currencystringThe currency
upsightDataobjectThe optional data to be set for monetization
Properties
NameTypeAttributesDescription
productstring<optional>
The name of the product
resolutionstring<optional>
The resolution of the purchase.One of: buy, cancel, fraud, or refund
eventDataobjectAny custom event data to be sent