How to create custom events in Analytics Cloud?

Issue

  • I would like to create a custom event, but after checking the official documentation, I am unsure about the steps.

Environment

  • Analytics Cloud
  • DXP 7.0+

Resolution

Please follow these steps to create a simple custom event.

DXP 7.0+

Widget Pages' JavaScript Field

  1. Go to your Liferay instance

  2. Click the Settings gear at the top of the page

  3. Click the Advanced tab

  4. Add the following JavaScript under the JavaScript section
    Analytics.track('eventName',{
    'propertyName': 'valueName'
    });
  5. Replace eventName with a custom name for your event that you can easily identify
    1. You can also replace propertyName and valueName to suit your needs
  6. Visit the page
    → Once you’ve saved this JavaScript code, it will fire every time you visit the page
  7. Check the custom events in Analytics Cloud

DXP 7.0+

Web Content

  1. Go to your Liferay instance
  2. Create a Web Content

  3. Copy and add the following JavaScript code to the Web Content via the Source editor

    <script>
    Analytics.track('eventName',{
    'propertyName': 'valueName'
    });
    </script>
  4. Replace eventName with a custom name for your event that you can easily identify
    1. You can also replace propertyName and valueName to suit your needs
  5. Save this Web Content

  6. Go to a page and add it, e.g. in a Web Content Display fragment
    Note: no content will actually be visible on the page

  7. Visit the page
    → Once you’ve saved this JavaScript code, it will fire every time you visit the page
  8. Check the custom events in Analytics Cloud

DXP 7.3+

Fragment

Create a fragment with the following code in the JavaScript field:

Analytics.track('eventName',{
'propertyName': 'valueName'
});

or this in the HTML field:

<script>
Analytics.track('neweventNameevent',{
'propertyName': 'valueName'
});
</script>

Results

Custom Event Results.png

eventName has been sent 20 times.png

Additional Information

 

Was this article helpful?
1 out of 1 found this helpful