- Source:
Countly object to manage the internal queue and send requests to Countly server. More information on https://resources.count.ly/docs/countly-sdk-for-web
Example
<script type="text/javascript">
//some default pre init
var Countly = Countly || {};
Countly.q = Countly.q || [];
//provide your app key that you retrieved from Countly dashboard
Countly.app_key = "YOUR_APP_KEY";
//provide your server IP or name. Use try.count.ly for EE trial server.
//if you use your own server, make sure you have https enabled if you use
//https below.
Countly.url = "https://yourdomain.com";
//start pushing function calls to queue
//track sessions automatically
Countly.q.push(["track_sessions"]);
//track sessions automatically
Countly.q.push(["track_pageview"]);
//load countly script asynchronously
(function() {
var cly = document.createElement("script"); cly.type = "text/javascript";
cly.async = true;
//enter url of script here
cly.src = "https://cdn.jsdelivr.net/countly-sdk-web/latest/countly.min.js";
cly.onload = function(){Countly.init()};
var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(cly, s);
})();
</script>
Namespaces
Members
(static) CountlyClass
- Source:
Countly class - exposing so plugins can extend its prototype
(static) DeviceIdType
- Source:
Properties:
Name | Type | Description |
---|---|---|
DEVELOPER_SUPPLIED |
||
SDK_GENERATED |
||
TEMPORARY_ID |
Possible device Id types are: DEVELOPER_SUPPLIED, SDK_GENERATED, TEMPORARY_ID
(static) onload
- Source:
Array of functions that are waiting to be notified that script has loaded and instantiated
Example
Countly.onload.push(function(){
console.log("script loaded");
});
(static) q
- Source:
Async api queue, push commands here to be executed when script is loaded or after
Example
Countly.q.push(['add_event',{
key:"asyncButtonClick",
segmentation: {
"id": ob.id
}
}]);
Methods
(static) deserialize(data) → {varies}
- Source:
Overwrite deserialization function for extending SDK with encryption, etc
Parameters:
Name | Type | Description |
---|---|---|
data |
string | value to deserialize |
Returns:
deserialized value
- Type
- varies
(static) getSearchQuery() → {string}
- Source:
Overwrite a way to get search query
Returns:
view url
- Type
- string
(static) getViewName() → {string}
- Source:
Overwrite a way to retrieve view name
Returns:
view name
- Type
- string
(static) getViewUrl() → {string}
- Source:
Overwrite a way to retrieve view url
Returns:
view url
- Type
- string
(static) init(conf) → {Object}
- Source:
- Deprecated:
- {number} [conf.max_logs=100] - maximum amount of breadcrumbs to store for crash logs
Initialize Countly object
Example
Countly.init({
//provide your app key that you retrieved from Countly dashboard
app_key: "YOUR_APP_KEY",
//provide your server IP or name. Use try.count.ly for EE trial server.
url: "http://yourdomain.com"
});
Parameters:
Name | Type | Description | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
conf |
Object | Countly initialization Init object with configuration options Properties
|
Returns:
countly tracker instance
- Type
- Object
(static) serialize(value) → {string}
- Source:
Overwrite serialization function for extending SDK with encryption, etc
Parameters:
Name | Type | Description |
---|---|---|
value |
any | value to serialize |
Returns:
serialized value
- Type
- string
add_consent(feature)
- Source:
Add consent for specific feature, meaning, user allowed to track that data (either core feature of from custom feature group)
Parameters:
Name | Type | Description |
---|---|---|
feature |
string | array | name of the feature, possible values, "sessions","events","views","scrolls","clicks","forms","crashes","attribution","users", etc or custom provided through Countly.group_features |
add_event(event)
- Source:
Report custom event
Parameters:
Name | Type | Description | ||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
event |
Object | Countly Event object Properties
|
add_log(record)
- Source:
Add new line in the log of breadcrumbs of what user did, will be included together with error report
Parameters:
Name | Type | Description |
---|---|---|
record |
string | any text describing what user did |
begin_session(noHeartBeat, force)
- Source:
Start session
Parameters:
Name | Type | Description |
---|---|---|
noHeartBeat |
boolean | true if you don't want to use internal heartbeat to manage session |
force |
bool | force begin session request even if session cookie is enabled |
cancel_event(key) → {boolean}
- Source:
Cancel timed event, cancels a timed event if it exists
Parameters:
Name | Type | Description |
---|---|---|
key |
string | event name that will canceled |
Returns:
- returns true if the event was canceled and false if no event with that key was found
- Type
- boolean
change_id(newId, merge)
- Source:
Change current user/device id
Parameters:
Name | Type | Description |
---|---|---|
newId |
string | new user/device ID to use. Must be a non-empty string value. Invalid values (like null, empty string or undefined) will be rejected |
merge |
boolean | move data from old ID to new ID on server |
check_any_consent() → {Boolean}
- Source:
Check if any consent is given, for some cases, when crucial parts are like device_id are needed for any request
Returns:
true is has any consent given, false if no consents given
- Type
- Boolean
check_consent(feature) → {Boolean}
- Source:
Check if consent is given for specific feature (either core feature of from custom feature group)
Parameters:
Name | Type | Description |
---|---|---|
feature |
string | name of the feature, possible values, "sessions","events","views","scrolls","clicks","forms","crashes","attribution","users" or custom provided through Countly.group_features |
Returns:
true if consent was given for the feature or false if it was not
- Type
- Boolean
collect_from_facebook(customopt)
- Source:
Collect information about user from Facebook, if your website integrates Facebook SDK. Call this method after Facebook SDK is loaded and user is authenticated.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
custom |
Object |
<optional> |
Custom keys to collected from Facebook, key will be used to store as key in custom user properties and value as key in Facebook graph object. For example, {"tz":"timezone"} will collect Facebook's timezone property, if it is available and store it in custom user's property under "tz" key. If you want to get value from some sub object properties, then use dot as delimiter, for example, {"location":"location.name"} will collect data from Facebook's {"location":{"name":"MyLocation"}} object and store it in user's custom property "location" key |
collect_from_forms(parentopt, useCustomopt)
- Source:
Collect possible user data from submitted forms. Add cly_user_ignore class to ignore inputs in forms or cly_user_{key} to collect data from this input as specified key, as cly_user_username to save collected value from this input as username property. If not class is provided, Countly SDK will try to determine type of information automatically.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
parent |
Object |
<optional> |
DOM object which children to track, by default it is document body |
|
useCustom |
boolean |
<optional> |
false
|
submit collected data as custom user properties, by default collects as main user properties |
enable_feedback(paramsopt)
- Source:
- Deprecated:
- use 'enableRatingWidgets' in place of this call
Show rating widget popup by passed widget ids array
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
params |
object |
<optional> |
required - includes "popups" property as string array of widgets ("widgets" for old versions) example params: {"popups":["5b21581b967c4850a7818617"]} |
enableRatingWidgets(paramsopt)
- Source:
Show rating widget popup by passed widget ids array
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
params |
object |
<optional> |
required - includes "popups" property as string array of widgets ("widgets" for old versions) example params: {"popups":["5b21581b967c4850a7818617"]} |
end_event(event)
- Source:
End timed event
Parameters:
Name | Type | Description |
---|---|---|
event |
string | object | event key if string or Countly event same as passed to Countly.add_event |
end_session(sec, force)
- Source:
End current session
Parameters:
Name | Type | Description |
---|---|---|
sec |
int | amount of seconds to report for current session, before ending it |
force |
bool | force end session request even if session cookie is enabled |
enrollUserToAb(keysopt)
- Source:
AB testing key provider, opts the user in for the selected keys
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
keys |
array |
<optional> |
Array of keys opt in FOR |
fetch_remote_config(keysopt, omit_keysopt, callbackopt)
- Source:
Fetch remote config from the server (old one for method=fetch_remote_config API)
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
keys |
array |
<optional> |
Array of keys to fetch, if not provided will fetch all keys |
omit_keys |
array |
<optional> |
Array of keys to omit, if provided will fetch all keys except provided ones |
callback |
function |
<optional> |
Callback to notify with first param error and second param remote config object |
get_available_feedback_widgets(callback)
- Source:
This function retrieves all associated widget information (IDs, type, name etc in an array/list of objects) of your app
Parameters:
Name | Type | Description |
---|---|---|
callback |
function | Callback function with two parameters, 1st for returned list, 2nd for error |
get_device_id() → {string}
- Source:
Gets the current device id
Returns:
device id
- Type
- string
get_device_id_type() → {number}
- Source:
Check and return the current device id type
Returns:
a number that indicates the device id type
- Type
- number
get_remote_config(keyopt) → {object}
- Source:
Gets remote config object (all key/value pairs) or specific value for provided key from the storage
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
key |
string |
<optional> |
if provided, will return value for key, or return whole object |
Returns:
remote configs
- Type
- object
getFeedbackWidgetData(CountlyFeedbackWidget, callback)
- Source:
Get feedback (nps, survey or rating) widget data, like questions, message etc.
Parameters:
Name | Type | Description |
---|---|---|
CountlyFeedbackWidget |
Object | Widget object, retrieved from 'get_available_feedback_widgets' |
callback |
function | Callback function with two parameters, 1st for returned widget data, 2nd for error |
group_features(features)
- Source:
Modify feature groups for consent management. Allows you to group multiple features under one feature group
Examples
Countly.group_features({all:["sessions","events","views","scrolls","clicks","forms","crashes","attribution","users"]});
//After this call Countly.add_consent("all") to allow all features
Countly.group_features({
activity:["sessions","events","views"],
interaction:["scrolls","clicks","forms"]
});
//After this call Countly.add_consent("activity") to allow "sessions","events","views"
//or call Countly.add_consent("interaction") to allow "scrolls","clicks","forms"
//or call Countly.add_consent("crashes") to allow some separate feature
Parameters:
Name | Type | Description |
---|---|---|
features |
object | object to define feature name as key and core features as value |
halt()
- Source:
WARNING!!! Should be used only for testing purposes!!!
Resets Countly to its initial state (used mainly to wipe the queues in memory). Calling this will result in a loss of data
initialize_feedback_popups(enableWidgetsopt)
- Source:
- Deprecated:
- use 'initializeRatingWidgets' in place of this call
Prepare rating widgets according to the current options
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
enableWidgets |
array |
<optional> |
widget ids array |
initializeRatingWidgets(enableWidgetsopt)
- Source:
Prepare rating widgets according to the current options
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
enableWidgets |
array |
<optional> |
widget ids array |
log_error(err, segmentsopt)
- Source:
Log an exception that you caught through try and catch block and handled yourself and just want to report it to server
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
err |
Object | error exception object provided in catch block |
|
segments |
string |
<optional> |
additional key value pairs you want to provide with error report, like versions of libraries used, etc. |
onStorageChange(key, newValue)
- Source:
Apply modified storage changes
Parameters:
Name | Type | Description |
---|---|---|
key |
String | key of storage modified |
newValue |
Varies | new value for storage |
opt_in()
- Source:
Opts in user for tracking, if complies with other user ignore rules like bot useragent and prefetch settings
opt_out()
- Source:
Opts out user of any metric tracking
present_feedback_widget(presentableFeedback, id, className)
- Source:
Present the feedback widget in webview
Parameters:
Name | Type | Description |
---|---|---|
presentableFeedback |
Object | Current presentable feedback |
id |
String | DOM id to append the feedback widget |
className |
String | Class name to append the feedback widget |
presentRatingWidgetWithID(id)
- Source:
Show specific widget popup by the widget id
Parameters:
Name | Type | Description |
---|---|---|
id |
string | id value of related rating widget, you can get this value by click "Copy ID" button in row menu at "Feedback widgets" screen |
recordDirectAttribution(campaign_idopt, campaign_user_idopt)
- Source:
Report user conversion to the server (when user signup or made a purchase, or whatever your conversion is), if there is no campaign data, user will be reported as organic
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
campaign_id |
string |
<optional> |
id of campaign, or will use the one that is stored after campaign link click |
campaign_user_id |
string |
<optional> |
id of user's click on campaign, or will use the one that is stored after campaign link click |
recordError(err, nonfatal, segments)
- Source:
Record and report error, this is were tracked errors are modified and send to the request queue
Parameters:
Name | Type | Description |
---|---|---|
err |
Error | Error object |
nonfatal |
Boolean | nonfatal if true and false if fatal |
segments |
Object | custom crash segments |
recordRatingWidgetWithID(ratingWidget)
- Source:
Provide information about user
Parameters:
Name | Type | Description | ||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
ratingWidget |
Object | object with rating widget properties Properties
|
remove_consent(feature, enforceConsentUpdate)
- Source:
Remove consent for specific feature, meaning, user opted out to track that data (either core feature of from custom feature group)
Parameters:
Name | Type | Description |
---|---|---|
feature |
string | array | name of the feature, possible values, "sessions","events","views","scrolls","clicks","forms","crashes","attribution","users", etc or custom provided through Countly.group_features |
enforceConsentUpdate |
Boolean | regulates if a request will be sent to the server or not. If true, removing consents will send a request to the server and if false, consents will be removed without a request |
report_conversion(campaign_idopt, campaign_user_idopt)
- Source:
- Deprecated:
- use 'recordDirectAttribution' in place of this call
Report user conversion to the server (when user signup or made a purchase, or whatever your conversion is), if there is no campaign data, user will be reported as organic
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
campaign_id |
string |
<optional> |
id of campaign, or will use the one that is stored after campaign link click |
campaign_user_id |
string |
<optional> |
id of user's click on campaign, or will use the one that is stored after campaign link click |
report_feedback(ratingWidget)
- Source:
- Deprecated:
- use 'recordRatingWidgetWithID' in place of this call
Provide information about user
Parameters:
Name | Type | Description | ||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
ratingWidget |
Object | object with rating widget properties Properties
|
report_orientation(orientationopt)
- Source:
Report device orientation
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
orientation |
string |
<optional> |
orientation as landscape or portrait |
report_trace(trace)
- Source:
Report performance trace
Parameters:
Name | Type | Description | ||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
trace |
Object | apm trace object Properties
|
reportFeedbackWidgetManually(CountlyFeedbackWidget, CountlyWidgetData, widgetResult)
- Source:
Report information about survey, nps or rating widget answers/results
Parameters:
Name | Type | Description |
---|---|---|
CountlyFeedbackWidget |
Object | it is the widget object retrieved from get_available_feedback_widgets |
CountlyWidgetData |
Object | it is the widget data object retrieved from getFeedbackWidgetData |
widgetResult |
Object | it is the widget results that need to be reported, different for all widgets, if provided as null it means the widget was closed widgetResult For NPS Should include rating and comment from the nps. Example: widgetResult = {rating: 3, comment: "comment"} widgetResult For Survey Should include questions ids and their answers as key/value pairs. Keys should be formed as “answ-”+[question.id]. Example: widgetResult = { "answ-1602694029-0": "Some text field long answer", //for text fields "answ-1602694029-1": 7, //for rating "answ-1602694029-2": "ch1602694029-0", //There is a question with choices like multi or radio. It is a choice key. "answ-1602694029-3": "ch1602694030-0,ch1602694030-1" //In case 2 selected } widgetResult For Rating Widget
Should include rating, email, comment and contact consent information. Example:
widgetResult = {
rating: 2,
email: "email@mail.com",
contactMe: true, |
session_duration(sec)
- Source:
Report session duration
Parameters:
Name | Type | Description |
---|---|---|
sec |
int | amount of seconds to report for current session |
show_feedback_popup(id)
- Source:
- Deprecated:
- use 'presentRatingWidgetWithID' in place of this call
Show specific widget popup by the widget id
Parameters:
Name | Type | Description |
---|---|---|
id |
string | id value of related rating widget, you can get this value by click "Copy ID" button in row menu at "Feedback widgets" screen |
start_event(key)
- Source:
Start timed event, which will fill in duration property upon ending automatically This works basically as a timer and does not create an event till end_event is called
Parameters:
Name | Type | Description |
---|---|---|
key |
string | event name that will be used as key property |
start_time()
- Source:
Start tracking duration time for this user, by default it is automatically tracked if you are using internal session handling
stop_time()
- Source:
Stop tracking duration time for this user
track_clicks(parentopt)
- Source:
Track all clicks on this page
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
parent |
Object |
<optional> |
DOM object which children to track, by default it is document body |
track_errors(segmentsopt)
- Source:
Automatically track javascript errors that happen on the website and report them to the server
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
segments |
string |
<optional> |
additional key value pairs you want to provide with error report, like versions of libraries used, etc. |
track_forms(parentopt, trackHiddenopt)
- Source:
Generate custom event for all forms that were submitted on this page
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
parent |
Object |
<optional> |
DOM object which children to track, by default it is document body |
trackHidden |
boolean |
<optional> |
provide true to also track hidden inputs, default false |
track_links(parentopt)
- Source:
Generate custom event for all links that were clicked on this page
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
parent |
Object |
<optional> |
DOM object which children to track, by default it is document body |
track_pageview(pageopt, ignoreListopt, viewSegmentsopt)
- Source:
Track page views user visits
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
page |
string |
<optional> |
optional name of the page, by default uses current url path |
ignoreList |
array |
<optional> |
optional array of strings or regexps to test for the url/view name to ignore and not report |
viewSegments |
object |
<optional> |
optional key value object with segments to report with the view |
track_scrolls(parentopt)
- Source:
Track all scrolls on this page
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
parent |
Object |
<optional> |
DOM object which children to track, by default it is document body |
track_sessions()
- Source:
Track user sessions automatically, including time user spent on your website
track_view(pageopt, ignoreListopt, segmentsopt)
- Source:
Track page views user visits. Alias of track_pageview method for compatibility with NodeJS SDK
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
page |
string |
<optional> |
optional name of the page, by default uses current url path |
ignoreList |
array |
<optional> |
optional array of strings or regexps to test for the url/view name to ignore and not report |
segments |
object |
<optional> |
optional view segments to track with the view |
user_details(user)
- Source:
Provide information about user
Parameters:
Name | Type | Description | ||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
user |
Object | Countly UserDetails object Properties
|