+ Start a Discussion
Doug Beltowski XDoug Beltowski X 

How to capture the URL of a webpage containing a Live Agent chat button?

We are implementing Live Agent with a pre-chat form to capture and display information from the customer.  The pre-chat form works great but we also want capture the URL the customer was on when they clicked the chat button.

I added some JavaScript to pass in this detail from the webpage.

`liveagent.addCustomDetail('URL', window.location.href);`

This works fine from a test HTML page on my desktop, but when we put the code on our testing website the URL doesn't get passed through.

On the webpage the code is in the `<body>` tag and looks like this.
<script type="text/javascript">
        if (!window._laq) { window._laq = []; }
        window._laq.push(function(){
            liveagent.showWhenOnline('573XXXXXXXXXXXX', document.getElementById('liveagent_button_online_573XXXXXXXXXXXX'));
            liveagent.showWhenOffline('573XXXXXXXXXXXX', document.getElementById('liveagent_button_offline_573XXXXXXXXXXXX'));
        });
    </script>
    <script type='text/javascript' src='https://c.la3-c2cs-chi.salesforceliveagent.com/content/g/js/37.0/deployment.js'></script>
    
    <script>
        // liveagent.addCustomDetail('URL', window.location.href); Doesn't work either
        window.onload=liveagent.addCustomDetail('URL', window.location.href);
    </script>
    
    <script type='text/javascript'>
        liveagent.init('https://d.la3-c2cs-chi.salesforceliveagent.com/chat', '572XXXXXXXXXXXX', '00DXXXXXXXXXXXX');
    </script>
I'm not JavaScript wiz so I'm not sure if/how much placement matters.

Also using FireFox firebug I see this error when I refresh the page

> ReferenceError: liveagent is not defined

I suspect this is caused by the `addCustomDetail` function but I'm not sure exactly how to find exactly where it is happening.

User-added image
SwarnaSankhaSinghSwarnaSankhaSingh
Hi Doug,

While implementing the Livechat functionality for our instance, one thing we did realize is that the feature is not very found of JS hacks. Now coming to your requirement in which you want to know which page a customer initiated the chat session. A very simple approach would be to have seperate Chat buttons for different pages provided the page list is not too huge in which case it does not make sense to take this approach. The advantage of having separate chat buttons gives us a good deal of control on routing as well as queue management.

May I ask the purpose of keeping track of the Orginating URL?

Kind Regards,
Swarna.