Track is used to record events. You should use this method to record each step of your conversion funnel.
Warning
- The JavaScript API (Client-Side) articles are intended for developers!
- Attribution should be installed by a developer.
- Attribution CANNOT be installed ONLY with Google Tag Manager.
- Do not minify or bundle Attribution snippet inside a webpack or it may render unstable in some conditions.
- Please try to avoid putting snippet inside a JS closure. You are still free to call
track()
from inside your JS app usingwindow.Attribution
variable.
Attribution.track(event, [properties], [callback]);
Parameter (type) | Description |
---|---|
event String | The name of the event |
properties Object, optional | A hashtable of properties describing the event. |
callback Object, optional | A callback function that gets called after a short timeout. |
Defining your Funnel
These events should describe the action taken in a way that would be recognizable to anyone in your company. Here’s some good examples of funnel events:
SAAS Funnel: Created Account, Completed Account Setup, Entered Credit Card, Purchased Subscription.
Shopping Cart Funnel: Added Item to Cart, Viewed Cart, Entered Credit Card, Completed Purchase.
Sending Properties Along With Events
Track allows you to send properties along with your events. We recommend sending meaningful properties along with your events to color the event with details of what happened. Here are some examples of the kind of properties you may want to send with a conversion event like Made a Purchase:
Order Total, Subscription Plan, Items In Cart, Number of Licenses
Making a track call is easy, a track call must have an event name and can include a optional array of properties. In the example below, we see a Converted event with the 'package' property set to 'pro'.
Attribution.track('Converted', {
package: 'pro'
});
Special Properties for Track: Revenue
Attribution app recognizes the revenue property on the track event and stores it in a special way. Revenue should be passed in the format [dollars].[cents] or 79.99 – just as it’s commonly written. Here’s an example of an event with the revenue property:
Attribution.track('Credit Card Charged', {
revenue: '79.99'
});
If you send negative revenue it will be handled like "refund" and will subtract from your total revenue.
Track Link
Sometimes you need to track a link that will cause a page reload before the tracking call can be completed. In this case you want to use trackLink. trackLink will wait to load the page until a callback is received from Attribution app or timeout has expired. The Attribution app timeout defaults to 100ms.
<div id="checkout">
<a href="/checkout">Checkout</a>
</div>
<script type="text/javascript">
Attribution.trackLink("#checkout", "Click Checkout");
</script>
Track Form
trackForm works the same way as trackLink by delaying the page reload and allowing the the tracking call to complete.
var createAccountForm = document.getElementById('createAccountForm');
Attribution.trackForm(createAccountForm, 'Created Account', {
Package: 'Enterprice',
Seats: 28
});