Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <script type='text/javascript'>
- //Enter conditions here to determine whether or not visitor is a registered user.
- window.isRegisteredUser = false;
- //Global variable to determine amount of time spent on site.
- var SECONDS_SPENT_ON_SITE = 120;
- olark('api.rules.defineRule', {
- // Specify a unique ID for this rule. This helps the API to keep your
- // rules separate from each other.
- id: '1',
- // The description is a good way to summarize what this rule is doing
- description: "offer help to a visitor after he has spent x amount of time on site and if he is not a registered user",
- // The condition will be checked whenever there is a relevant change
- // in the chat, just call pass() whenever it meets the criteria
- condition: function(pass) {
- // you can use the Visitor API to get information like page count, seconds spent on site, etc.
- olark('api.visitor.getDetails', function(details){
- if (details.secondsSpentForThisVisit >= SECONDS_SPENT_ON_SITE && !details.isConversing && !window.isRegisteredUser) {
- // we have met the condition of time spent is over SECONDS_SPENT_ON_SITE,
- // and the visitor has not started chatting yet,
- // and the visitor is not a registered user
- // so mark this condition as passed
- pass();
- }
- });
- },
- // The action will be executed whenever the condition passes. You can
- // automatically limit the number of times this action will trigger by
- // using the perPage, perVisit, and perVisitor options.
- action: function() {
- olark('api.chat.sendMessageToVisitor', {
- body: "Hi, have any questions about our products?"
- });
- },
- // Restrict the action to execute only once per visit, that way offering
- // help doesn't happen over and over for the same visitor
- perVisit: true
- });
- </script>
Add Comment
Please, Sign In to add comment