Conversion tracking via JavaScript

If you want to track conversions in a third-party platform, you can use our Checkout Javascript API to attach an event handler for all orders placed.


How to track conversions

Once you've installed your general tracking code (available here: https://giftup.app/installation), you just add an extra line of code to track all gift card orders (a.k.a. conversions). We'll pass in a data object representing the order and you can extract the parameters you need from it as required. 

giftup("conversion", function (payload) { 
    console.log(payload); 
    // Fire your event here... 
});

Conversion tracking payload definition

When specifying your function to track conversion events, we'll pass in an object representing the order that's just been placed (labeled as 'payload' in the example above) with the following properties on it:

orderId (string) a Guid representing our internal OrderId
currency (string) the currency of the order
revenue (number) the total paid for the order
giftCards (array of giftCard objects) represents the gift cards in the order

A single giftCard has the following properties on it:

id (string) a Guid representing our internal Id for the gift card
code (string) the code on the gift card
item (string) the name of the item bought
sku (string) the item sku (if specified in the dashboard)
price (number) the total paid for the individual gift card

{
    orderId: "d61d9053-5801-48ee-963c-b080f0eda8f1",
    currency: "USD",
    revenue: 200.00,
    giftCards: [
        {
            id: "42e28ff4-5eb8-4dab-a4c6-75442deadbac",
            code: "ABC123",
            item: "$50 Gift Card",
            sku: "50-gc",
            price: 50.00,
        },
        {
            id: "3cb1fa06-c9f3-4916-bb9c-3c70c75470e1",
            code: "CDE456",
            item: "$150 Gift Card",
            sku: null,
            price: 150.00,
        }
    ]
}

Full example

Here's a full example of how to track conversions in Google Analytics (for example):

<script type="text/javascript"> 
(function(g, i, f, t, u, p, s) {
    g[u] = g[u] || function() {
        (g[u].q = g[u].q || []).push(arguments)
    };
    p = i.createElement(f);
    p.async = 1;
    p.src = t;
    s = i.getElementsByTagName(f)[0];
    s.parentNode.insertBefore(p, s);
})(window, document, 'script', 'https://cdn.giftup.app/dist/gift-up.js', 'giftup');

// Track conversions: 
giftup("conversion", function(payload) {
    ga('require', 'ecommerce');
    var transaction = {
        'id': payload.orderId,
        'affiliation': 'Gift Up!',
        'revenue': payload.revenue.toString(),
        'shipping': '0',
        'tax': '0',
        'currency': payload.currency.toUpperCase()
    };

    ga('ecommerce:addTransaction', transaction);

    for (var i = 0; i < payload.giftCards.length; i++) {
        let giftCard = payload.giftCards[i];
        let gaItem = {
            'id': payload.orderId,
            'name': giftCard.code + ' - ' + giftCard.item,
            'sku': giftCard.code, // needs to be unique in order to track all items https://stackoverflow.com/questions/19954083/google-analytics-ecommerce-sends-only-last-item-in-transaction
            'category': '',
            'price': giftCard.price,
            'quantity': '1',
            'currency': payload.currency.toUpperCase()
        };

        ga('ecommerce:addItem', gaItem);
    }

    ga('ecommerce:send');
});
</script>
Did this answer your question? Thanks for the feedback There was a problem submitting your feedback. Please try again later.

Still need help? Contact Us Contact Us