Skip to main content

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. Optional
    • duration : Set the operation time. For the operation sent immediately, you can set this configuration specified operation time. Number type. Optional
    • timeout : 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. Optional
  • context : The additional data contained in the operation. Object type. Optional
  • status : Set the operation status success or fail , default success . String type. Optional
  • fail : End in the state of failure
action.fail(options);
  • options : End the operating configuration object. Optional
  • context : The additional data contained in the operation. Object type. Optional
  • store : Temporary operation, the operation related information will be preserved localStorage Middle, can be used window.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. Optional
  • key : End the operation of the specified key, and the operation of the current storage is not passed. The string type. Optional
  • status : Specify the end of the storage operation. success or fail . String type. Optional
  • timeout : 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:

NameWhether it is necessaryillustrate
keynoAutomatically end the event key, and pass only to end the specified key event.
statusnoAutomatically end the event status. Default is success. Success: Success, Failure: FAIL
TimeoutnoCross -noodle event timeout time, default 60s, no timeout data

The processing method of cross -page events and some attention issues:

  1. 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.
  2. 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.
  3. Page 1 and page 2 need to be at the same time.
  4. Page 1 and page 2 cannot be cross -domain.