Operating configuration
Users can clicks on an interactive element that can be clicked, such as registration, adding shopping carts, downloading, mobile advertising clicks, small tools, Flash elements, AJAX embedded elements, and video playback. The time -consuming experience during the operation.
Event is divided into two categories:
-
Automatically create events: You can directly specify the name of the event as the event name, and the same KEY event will be attributed to an event.
-
Cross -page events.
Configure fault tolerance code
The basis of event monitoring is that the application must be embedded and loaded the browser JS probe. Therefore, in order to prevent the probe from removing or not loaded the event monitoring error caused by early calls, please add fault tolerance code before the event code. The code is as follows:
//Fault tolerance code, declare once per page, to handle fault tolerance when tingyun_rum.js is removed
if(!window.TINGYUN){window.TINGYUN={};window.TINGYUN.newAction=function(){var e={};e.end=function(){};e.fail=function(){};e.store=function(){};return e};window.TINGYUN.endStoreEvent=function(){}};
If you do not add a fault tolerance code, it is recommended to judge the interface available before calling the interface:
For example:
if (window.TINGYUN && window.TINGYUN.newAction) {
window.TINGYUN.newAction({
...
});
}
User custom operation
grammar:
const action = window.TINGYUN.newAction(options[, immediate]);
parameter:
- options
Operation configuration item object
key
: Operation name. String type.context
: The additional data contained in the operation. Object type. Optionalduration
: Set the operation time. For the operation sent immediately, you can set this configuration specified operation time. Number type. Optionaltimeout
: Operation timeout time, 10 minutes by default, operation after timeout cannot end, Number type, optional available
- Immediant Whether to send this operation immediately, Boolean type, default to false. Optional
return:
Returns the operation object ACTION, which can be used to end the operation. The action object contains the following functions.
end
: End operation
action.end(options);
options
: End the operating configuration object. Optionalcontext
: The additional data contained in the operation. Object type. Optionalstatus
: Set the operation statussuccess
orfail
, defaultsuccess
. String type. Optionalfail
: End in the state of failure
action.fail(options);
options
: End the operating configuration object. Optionalcontext
: The additional data contained in the operation. Object type. Optionalstore
: Temporary operation, the operation related information will be preservedlocalStorage
Middle, can be usedwindow.TINGYUN.endStoredAction
Read and end. It is mainly used for cross -page operation. End storage operation:
action.store();
window.TINGYUN.endStoredAction(options);
options
: End the storage operation configuration object. Optionalkey
: End the operation of the specified key, and the operation of the current storage is not passed. The string type. Optionalstatus
: Specify the end of the storage operation.success
orfail
. String type. Optionaltimeout
: Set timeout time, default 60s, if no timeout data is uploaded. Number type. Optional available
Example:
Example of scenario of submitting orders:
function submitOrder(order) {
// Create a submit order operation and pass the order ID as additional information
const action = window.TINGYUN.newAction({
key: 'Submit Order',
context: {
orderId: order.id
}
});
// Custom business logic for the submit order request
sendRequest(SUBMIT_ORDER_URL, data)
.then((res) => {
// Submission successful, end the operation and set the additional business status code returned
action.end({
context: {
code: res.data.code
}
});
})
.catch(() => {
// Submission failed, end the operation with a failure status
action.fail();
});
}
Cross -page event
If the incident is across the page under the same domain conditions, you need to use a cross -page event API (the cross -page event API can also be used on the same page, but the general usage method is more efficient and simpler. Therefore This API).
Code example:
Page 1:
const action = window.TINGYUN.newAction({
key: 'Cross-Page Event'
});
// Execute logic
// After the logic is executed, do not use end or fail, use store to temporarily save the current event
action.store(); // At this point, the event has not ended
// Subsequent logic to navigate to Page 2...
Page 2:
// End the event after Page 2 has finished loading
window.addEventListener('load', function() {
if (window.TINGYUN && typeof window.TINGYUN.endStoredAction === 'function') {
window.TINGYUN.endStoredAction({
key: 'Cross-Page Event', // Must correspond to the event on Page 1; if not passed, the most recently stored event will be ended
status: 'success', // 'success' or 'fail' indicates the status of the event
timeout: 60000 // The event timeout period in milliseconds; if it times out, it will not be uploaded; default is 60 seconds if not specified
});
}
});
If the parameters are not passed, the recently storage event is completed by default, and the status is successful.
window.TINGYUN.endStoredAction();
Interface Description:
window.TINGYUN.endStoredAction(); // Call without parameters
window.TINGYUN.endStoredAction(options); // Call with parameters
endStoredAction
Options object parameter description:
Name | Whether it is necessary | illustrate |
---|---|---|
key | no | Automatically end the event key, and pass only to end the specified key event. |
status | no | Automatically end the event status. Default is success. Success: Success, Failure: FAIL |
Timeout | no | Cross -noodle event timeout time, default 60s, no timeout data |
The processing method of cross -page events and some attention issues:
- There can only be one across page event at the same time. Each time you call the store function, the current cross -page event will use a new event to replace it.
- The probe data request will be sent on the page of the end of the event. If the end of the event page is not the same page as the starting event page, it will silently recognize adding a page loading information as a network request upload.
- Page 1 and page 2 need to be at the same time.
- Page 1 and page 2 cannot be cross -domain.