In the example below, we have two links that will track events and one trackEvent defined inline.
Note: choose View1 or View2 from the top right corner. Notice network tab for json?... requests
-
Description
You can define event tracking inline (no prevent default):
<a onclick="adobe.target.trackEvent({ mbox: 'myMboxName', success:function(){ alert('example#1. Look at url. It is already changed.') } })" href="#view1">switch to view1 (no prevent default)</a>
Inline, with prevent default action.
<a href="#view2" onclick="adobe.target.trackEvent({ mbox: 'myMboxName', event: event, preventDefault: true, success: function(){ alert('example#2. Look at url. It will change after clicking ok'); }})">switch to view2 (with prevent default)</a>
or assign it to multiple elements by using selector, type parameters
<a href="#view1" class="trackEventClass">switch to view1 (with prevent default)</a> <a href="#view2" class="trackEventClass">switch to view2 (with prevent default)</a> <script> adobe.target.trackEvent({ mbox: 'myMboxName', type: 'click', selector: '.trackEventClass', preventDefault: true, // works only for [a:click, form:submit] element:event combinations success: function() { alert('example#3. Look at url. It will change after clicking ok'); } }); </script>
1. Inline, no prevent default action. Meaning you will see url changed before an alert.
2. Inline, with prevent default action. Meaning you will see an alert before url changed.
3. Outline. Assign track event (prevent default: on) to multiple elements.