Methods
(static) init(options)
Initialize Analytics and set up the general configurations.
- Source:
Parameters:
Name | Type | Description | ||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
Object
|
(see attributes below)
|
Examples
// Logger
// Analytics with console as logger
AnalyticsAdapter.init({
enabled: true,
analyticsID: 'UA-123456789-1',
logger: console,
dimensions: {
'UserStatus': 1,
'AccessType': 2,
'Valuable': 5,
'Action': 8,
'PaymentType': 11
}
});
// Analytics with no logs
AnalyticsAdapter.init({
enabled: true,
analyticsID: 'UA-123456789-1',
dimensions: {
'UserStatus': 1,
'AccessType': 2,
'Valuable': 5,
'Action': 8,
'PaymentType': 11
}
});
// Custom Dimensions
// In analytics initialization phase, you have to define all custom dimensions
// that you will use in your applications.
// Init method doesn't set custom dimension on Google Analytics, it only saves
// custom dimension for future use (for example in event tracking).
// You have to pass a pair (custom dimension name, slot id), where slot id is the slot
// of the custom dimension assigned from Google Analytics before.
// In this example, I set two custom dimensions ("UserStatus" with slot number 1
// and "Valuable" with slot number 5):
AnalyticsAdapter.init({
enabled: true,
dimensions: {
'UserStatus' : 1,
'Valuable' : 5
}
});
(static) setDimension(dimensions)
Set a user/session (not hit) custom dimension.
- Source:
Parameters:
Name | Type | Description | |||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
dimensions |
Array.<Object>
|
|
Example
// The custom dimension has to be defined in init method before
// and, after, you have to use the same custom dimension name.
// For example, in the following code, I set UserStatus on slot number 1 and
// assign it the logged value:
// before, I save UserStatus custom dimension with slot "1"
Analytics.init({
dimensions: {
'UserStatus' : 1
}
});
// after, I set custom dimension with the logged value:
AnalyticsAdapter.setDimension({
'UserStatus' : 'logged'
});
(static) setId(id)
Set Analytics user id
- Source:
Parameters:
Name | Type | Description |
---|---|---|
id |
string
|
user id |
Example
AnalyticsAdapter.setId("123rgr");
(static) trackEvent(options)
Track an event
- Source:
Parameters:
Name | Type | Description | |||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
Object
|
(see attributes below)
|
Example
// Note: the custom dimension (in this example Valuable)
// has to be defined in the init method first and you have to use the same custom dimension name.
AnalyticsAdapter.trackPage({
category: 'UI',
action: 'open',
label: 'menu',
value: 7,
dimensions: {
'Valuable': 'yes'
}
});
(static) trackPage(options)
Track pageview events with optional custom dimensions
- Source:
Parameters:
Name | Type | Description | |||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
Object
|
The trackPage options
|
Example
// Note: the custom dimension (in this example Valuable)
// has to be defined in the init method first and you have to use the same custom dimension name.
AnalyticsAdapter.trackPage({
page: '/home',
title: 'Home Page',
dimensions: {
dimensionOne: 'logged',
dimensionFour: 'premium',
}
});