Tracking Events example

Info

This example shows how to track events for either "Click", "AddToCart" or "Purchase".

It is required to provide EntityType and ExternalId of the product you are tracking, so that we can put everything together correctly.

Dependencies for this example:

1. Add product to track

2. Set EventType

3. Track the event

4. Check result

Request Parameters sent to loop54-js-lib


    

Response


  

Show code ▼



If you haven't included loop54-js-lib already, include this part and configure it to talk to your loop54 proxy
<script type="text/javascript" src="loop54-js-lib.js"></script>
<script type="text/javascript">
  Loop54.setConfig({url: "https://helloworld.54proxy.se"}); // you will get this config from us when we have set up an engine
</script>
Then include the tracking function in a separate javascript file or last in your HTML body tag
<script type="text/javascript">
  function track(entities, eventType) {
    if(typeof(entities) === "string") { entities = JSON.parse(entities); };
    var requestParameters = {
      Events: entities.map(function(entity) {
        return {
          Type: eventType,
          Entity: {
            EntityType: entity.EntityType,
            ExternalId: entity.ExternalId,
          },
        }
      }),
      QuestName: "CreateEvents",
    };

    Loop54.getResponse(requestParameters).then(function(response) {
      // here you can put success messages, it"s not required to do anything after an event is sent.
    });
  };
</script>