3.2.3Initialize a new Alias facade with a dictionary of arguments.
Extends Facade
(Object)
The object to wrap.
| Name | Description |
|---|---|
dictionary.from string?
|
The previous ID of the user. |
dictionary.to string?
|
The new ID of the user. |
(Object)
Options about what kind of Facade to create.
An alias for Alias#action.
string:
An alias for Alias#previousId.
string:
An alias for Alias#userId.
string:
Initialize a new Delete facade with a dictionary of arguments.
Extends Facade
(Object)
The object to wrap.
| Name | Description |
|---|---|
dictionary.category string?
|
The delete category. |
dictionary.name string?
|
The delete name. |
dictionary.properties string?
|
The delete properties. |
(Object)
Options about what kind of Facade to create.
A Facade is an object meant for creating convience wrappers around objects. When developing integrations, you probably want to look at its subclasses, such as Track or Identify, rather than this general-purpose class.
This constructor will initialize a new Facade with an obj of arguments.
If the inputted obj doesn't have a timestamp property, one will be added
with the value new Date(). Otherwise, the timestamp property will be
converted to a Date using the new-date package.
By default, the inputted object will be defensively copied, and all ISO strings present in the string will be converted into Dates.
(Object)
The object to wrap.
(Object)
Options about what kind of Facade to create.
| Name | Description |
|---|---|
opts.clone boolean
(default true)
|
Whether to make defensive clones. If enabled, the inputted object will be cloned, and any objects derived from this facade will be cloned before being returned. |
opts.traverse boolean
(default true)
|
Whether to perform ISODate-Traverse on the inputted object. |
Create a helper function for fetching a "plural" thing.
The generated method will take the inputted path and append an "s" to it
and calls this.proxy with this "pluralized" path. If that produces an
array, that will be returned. Otherwise, a one-element array containing
this.proxy(path) will be returned.
(string)
Function:
MyClass.prototype.birds = Facade.multi('animals.bird');
Create a helper function for getting a "singular" thing.
The generated method will take the inputted path and call
this.proxy(path). If a truthy thing is produced, it will be returned.
Otherwise, this.proxy(path + 's') will be called, and if that produces an
array the first element of that array will be returned. Otherwise,
undefined is returned.
(string)
Function:
MyClass.prototype.bird = Facade.one('animals.bird');
Get a potentially-nested field in this facade. field should be a
period-separated sequence of properties.
If the first field passed in points to a function (e.g. the field passed
in is a.b.c and this facade's obj.a is a function), then that function
will be called, and then the deeper fields will be fetched (using obj-case)
from what that function returns. If the first field isn't a function, then
this function works just like obj-case.
Because this function uses obj-case, the camel- or snake-case of the input is irrelevant.
any:
A property of the inputted object.
YourClass.prototype.height = function() {
return this.proxy('getDimensions.height') ||
this.proxy('props.size.side_length');
}
Get the options of a call. If an integration is passed, only the options for
that integration are included. If the integration is not enabled, then
undefined is returned.
Options are taken from the options property of the underlying object,
falling back to the object's context or simply {}.
(string)
The name of the integration to get settings
for. Casing does not matter.
(Object | undefined):
An alias for Facade#options.
Check whether an integration is enabled.
Basically, this method checks whether this integration is explicitly enabled. If it isn'texplicitly mentioned, it checks whether it has been enabled at the global level. Some integrations (e.g. Salesforce), cannot enabled by these global event settings.
More concretely, the deciding factors here are:
this.integrations() has the integration set to true, return true.this.integrations().providers has the integration set to true, return true.options.providers.all, options.all, or integrations.all), then return
false.(string)
boolean:
Get sessionId / anonymousId.
any:
An alias for Facade#anonymousId.
string:
Get the call's "traits". All event types can pass in traits, though Identify and Group override this implementation.
Traits are gotten from options.traits, augmented with a property id with
the event's userId.
The parameter aliases is meant to transform keys in options.traits into
new keys. Each alias like { "xxx": "yyy" } will take whatever is at xxx
in the traits, and move it to yyy. If xxx is a method of this facade,
it'll be called as a function instead of treated as a key into the traits.
(Object)
A mapping from keys to the new keys they should be
transformed to.
Object:
var obj = { options: { traits: { foo: "bar" } }, anonymousId: "xxx" }
var facade = new Facade(obj)
facade.traits() // { "foo": "bar" }
facade.traits({ "foo": "asdf" }) // { "asdf": "bar" }
facade.traits({ "sessionId": "rofl" }) // { "rofl": "xxx" }
Get the User-Agent from context.userAgent.
This should be a string, but may not be if the client isn't adhering to the spec.
any:
string
Get the timezone from context.timezone.
This should be a string, but may not be if the client isn't adhering to the spec.
any:
string
Get the timestamp from context.timestamp.
any:
string
Get the channel from channel.
This should be a string, but may not be if the client isn't adhering to the spec.
any:
string
Get the IP address from context.ip.
This should be a string, but may not be if the client isn't adhering to the spec.
any:
string
Get the user ID from userId.
This should be a string, but may not be if the client isn't adhering to the spec.
any:
string
Initialize a new Group facade with a dictionary of arguments.
Extends Facade
(Object)
The object to wrap.
| Name | Description |
|---|---|
dictionary.userId string?
|
The user to add to the group. |
dictionary.groupId string?
|
The ID of the group. |
dictionary.traits Object?
|
The traits of the group. |
(Object)
Options about what kind of Facade to create.
An alias for Group#action.
string:
Get the group ID from groupId.
This should be a string, but may not be if the client isn't adhering to the spec.
string:
Get the group's traits. This is identical to how Facade#traits
works, except it looks at traits.* instead of options.traits.*.
Traits are gotten from traits, augmented with a property id with
the event's groupId.
The parameter aliases is meant to transform keys in traits into new
keys. Each alias like { "xxx": "yyy" } will take whatever is at xxx in
the traits, and move it to yyy. If xxx is a method of this facade, it'll
be called as a function instead of treated as a key into the traits.
(Object)
A mapping from keys to the new keys they should be
transformed to.
Object:
var obj = { traits: { foo: "bar" }, anonymousId: "xxx" }
var group = new Group(obj)
group.traits() // { "foo": "bar" }
group.traits({ "foo": "asdf" }) // { "asdf": "bar" }
group.traits({ "sessionId": "rofl" }) // { "rofl": "xxx" }
Initialize a new Identify facade with a dictionary of arguments.
Extends Facade
(Object)
The object to wrap.
| Name | Description |
|---|---|
dictionary.userId string?
|
The ID of the user. |
dictionary.anonymousId string?
|
The anonymous ID of the user. |
dictionary.traits string?
|
The user's traits. |
(Object)
Options about what kind of Facade to create.
An alias for Identify#action.
string:
Get the user's traits. This is identical to how Facade#traits works,
except it looks at traits.* instead of options.traits.*.
Traits are gotten from traits, augmented with a property id with
the event's userId.
The parameter aliases is meant to transform keys in traits into new
keys. Each alias like { "xxx": "yyy" } will take whatever is at xxx in
the traits, and move it to yyy. If xxx is a method of this facade, it'll
be called as a function instead of treated as a key into the traits.
(Object)
A mapping from keys to the new keys they should be
transformed to.
Object:
var obj = { traits: { foo: "bar" }, anonymousId: "xxx" }
var identify = new Identify(obj)
identify.traits() // { "foo": "bar" }
identify.traits({ "foo": "asdf" }) // { "asdf": "bar" }
identify.traits({ "sessionId": "rofl" }) // { "rofl": "xxx" }
Get the user's name traits.name, falling back to combining Identify#firstName and Identify#lastName if possible.
This should be a string, but may not be if the client isn't adhering to the spec.
string:
Get the user's first name from traits.firstName, optionally splitting it
out of a the full name if that's all that was provided.
Splitting the full name works on the assumption that the full name is of the form "FirstName LastName"; it will not work for non-Western names.
This should be a string, but may not be if the client isn't adhering to the spec.
string:
Get the user's last name from traits.lastName, optionally splitting it out
of a the full name if that's all that was provided.
Splitting the full name works on the assumption that the full name is of the form "FirstName LastName"; it will not work for non-Western names.
This should be a string, but may not be if the client isn't adhering to the spec.
string:
Initialize a new Page facade with a dictionary of arguments.
Extends Facade
(Object)
The object to wrap.
| Name | Description |
|---|---|
dictionary.category string?
|
The page category. |
dictionary.name string?
|
The page name. |
dictionary.properties string?
|
The page properties. |
(Object)
Options about what kind of Facade to create.
An alias for Page#action.
string:
Get the page category from category.
This should be a string, but may not be if the client isn't adhering to the spec.
string:
Get the page name from name.
This should be a string, but may not be if the client isn't adhering to the spec.
string:
Get the page title from properties.title.
This should be a string, but may not be if the client isn't adhering to the spec.
string:
Get the page path from properties.path.
This should be a string, but may not be if the client isn't adhering to the spec.
string:
Get the page URL from properties.url.
This should be a string, but may not be if the client isn't adhering to the spec.
string:
Get the page's properties. This is identical to how Facade#traits
works, except it looks at properties.* instead of options.traits.*.
Properties are gotten from properties, augmented with the page's name
and category.
The parameter aliases is meant to transform keys in properties into new
keys. Each alias like { "xxx": "yyy" } will take whatever is at xxx in
the traits, and move it to yyy. If xxx is a method of this facade, it'll
be called as a function instead of treated as a key into the traits.
(Object)
A mapping from keys to the new keys they should be
transformed to.
Object:
var obj = { properties: { foo: "bar" }, anonymousId: "xxx" }
var page = new Page(obj)
page.traits() // { "foo": "bar" }
page.traits({ "foo": "asdf" }) // { "asdf": "bar" }
page.traits({ "sessionId": "rofl" }) // { "rofl": "xxx" }
Convert this Page to a Track facade. The inputted name will be
converted to the Track's event name via Page#event.
(string)
Track:
Initialize a new Screen facade with a dictionary of arguments.
Note that this class extends Page, so its methods are available to instances of this class as well.
Extends Page
(Object)
The object to wrap.
| Name | Description |
|---|---|
dictionary.category string?
|
The page category. |
dictionary.name string?
|
The page name. |
dictionary.properties string?
|
The page properties. |
(Object)
Options about what kind of Facade to create.
An alias for Screen#action.
string:
Convert this Screen to a Track facade. The inputted name will be
converted to the Track's event name via Screen#event.
(string)
Track:
Initialize a new Track facade with a dictionary of arguments.
Extends Facade
(Object)
The object to wrap.
| Name | Description |
|---|---|
dictionary.event string?
|
The name of the event being tracked. |
dictionary.userId string?
|
The ID of the user being tracked. |
dictionary.anonymousId string?
|
The anonymous ID of the user. |
dictionary.properties string?
|
Properties of the track event. |
(Object)
Options about what kind of Facade to create.
An alias for Track#action.
string:
Get the subtotal for this purchase from properties.subtotal.
If properties.subtotal isn't available, then fall back to computing the
total from properties.total or properties.revenue, and then subtracting
tax, shipping, and discounts.
If neither subtotal, total, nor revenue are available, then return 0.
number:
Get the page's properties. This is identical to how Facade#traits
works, except it looks at properties.* instead of options.traits.*.
Properties are gotten from properties.
The parameter aliases is meant to transform keys in properties into new
keys. Each alias like { "xxx": "yyy" } will take whatever is at xxx in
the traits, and move it to yyy. If xxx is a method of this facade, it'll
be called as a function instead of treated as a key into the traits.
(Object)
A mapping from keys to the new keys they should be
transformed to.
Object:
var obj = { properties: { foo: "bar" }, anonymousId: "xxx" }
var track = new Track(obj)
track.traits() // { "foo": "bar" }
track.traits({ "foo": "asdf" }) // { "asdf": "bar" }
track.traits({ "sessionId": "rofl" }) // { "rofl": "xxx" }
Get the revenue for this event.
If this is an "Order Completed" event, this will be the properties.total
falling back to the properties.revenue. For all other events, this is
simply taken from properties.revenue.
If there are dollar signs in these properties, they will be removed. The result will be parsed into a number.
number:
Get the revenue for this event in "cents" -- in other words, multiply the Track#revenue by 100, or return 0 if there isn't a numerical revenue for this event.
number: