Note: This documentation is for Opentracker's events engine, please contact us if you think you need an upgrade.

Using javascript to send a event on page-load

Note: to submit the event on document ready, you can use either a existing library like jQuery or construct your own.

<!-- Load the jQuery library in order to submit the event after the document is ready -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js">            
                                
<!-- Load the Opentracker javascript before you define the custom variable -->
<script src="https://script.opentracker.net/?site=test.opentracker.net">

<script type="text/javascript">

        $(document).ready(function() {
                var map = new OTMap();
                map.put("firstName", "John");
                map.put("lastName", "Doe");
                OTLogService.sendEvent("Name captured", map);
        });
</script>

Using javascript to send a form event

Lets create a form text field with a submit button.

<form id="form1" name="form1" method="post" action="">
    <label>
      Send an event from a text box:
        </label>
    <input name="textbox" type="text" id="exampleTextbox" value="enter a test message" size="50" />
    <input type="button" name="seeActivityStream" id="seeActivityStream" value="Click to send text" onclick="sendTextForm()" />
</form>

And then you can submit the event with the filled in form value to Opentracker's event engine like this:

                           
<!-- Load the Opentracker javascript before you define the custom variable -->
<script src="https://script.opentracker.net/?site=test.opentracker.net">

<script type="text/javascript">

function sendTextForm() {

  // create a new Opentracker events object called "map"
  var map = new OTMap();

  // fill the map objects with values 
  map.put("ti", "Send Text button clicked");

  // with getElementById you can get the data from all the form events
  var exampleTextbox = document.getElementById("exampleTextbox").value;

  // add the form field to the map  
  map.put("myFormTextbox", exampleTextbox);

  // send the data
  OTLogService.sendEvent("Send Text button clicked", map);
  
}       
</script>

For a complete example on how to submit form fields go here

We would love to hear your feedback. Please use the facebook comment box below