Clients using Shopify can implement FindMine Transaction Analytics by setting up a Custom Pixel on their Storefront. Shopify Pixels are JavaScript code snippets that run during specified customer events in Shopify’s checkout. For FindMine Transaction Analytics, a Custom Pixel involves sending an API request with a customer’s order information to the FindMine Analytics endpoint when that customer completes their checkout.

Please note that a Shopify developer, or someone with deep familiarity with your Shopify Storefront’s settings, should set up this Custom Pixel.

Additionally, this implementation guide assume you are using a PDP Widget for your FindMine integration.

Implementation Steps

  1. Navigate to Settings > Customer Events > Add custom pixel and name the pixel FindMine Transaction

    <aside> ☝ Because FindMine is considered a data subprocessor to your business and FindMine does not sell your data, we suggest using the following Customer Privacy settings

    </aside>

    Customer_Privacy_Shopify.png

  2. Under Customer Privacy > Permission, the developer can select Not required

  3. Under Customer Privacy > Data sale, the developer can select Data collected does not qualify as data sale

  4. In the Code section, the Shopify developer should copy-and-paste the following FindMine transaction code:

    analytics.subscribe('checkout_completed', (event) => {
        const checkout = event.data.checkout;
    
        const transactionUrl = '<https://api.findmine.com/api/v3/analytics?event_type=transaction>';
    
        const fmApplication = ''; // Enter your FindMine Application ID here
    
        let query = '&application=' + fmApplication;
        query += '&session_id=' + _getFindMineCookie();
        query += '&customer_id=' + checkout.order?.customer?.id;
        query += '&transaction_id=' + checkout.order?.id;
        query += '&total_price=' + checkout.subtotalPrice.amount;
    
        // NOTE: checkout.discountsAmount is only available if your store has upgraded to Checkout Extensibility
        // (Cont.) If your store has not upgraded to Checkout Extensibility, remove the following line
        query += '&total_discount=' + checkout.discountsAmount?.amount;
    
        // NOTE: The following fields are optional unless your store is outside of the US
        // 2-letter ISO country code; this is available in the checkout object if your store has upgraded to Checkout Extensibility
        query += '&country=' + checkout.localization?.country?.isoCode;
        // 2-letter ISO language code; this is available in the checkout object if your store has upgraded to Checkout Extensibility
        query += '&language=' + checkout.localization?.language?.isoCode;
        // 3-letter ISO-4217 code
        query += '&currency=' + checkout.currencyCode;
    
        const itemData = {
            'product_ids': [],
            'product_skus': [],
            'product_quantities': [],
            'product_prices': [],
            'product_list_prices': [],
        }
    
        checkout.lineItems.forEach((lineItem, index) => {
            itemData.product_ids.push(lineItem.variant.id);
            itemData.product_skus.push(lineItem.variant.sku);
            itemData.product_quantities.push(lineItem.quantity);
            // NOTE: lineItem.finalLinePrice is only available if your store has upgraded to Checkout Extensibility
            // (Cont.) If your store has not upgraded to Checkout Extensibility, use the following line instead
            // itemData.product_prices.push(lineItem.variant.price.amount);
            itemData.product_prices.push(lineItem.finalLinePrice?.amount);
            itemData.product_list_prices.push(lineItem.variant.price.amount);
        });
    
        Object.keys(itemData).forEach((key) => {
            query += '&' + key + '=' + itemData[key].join(',');
        });
    
        fetch(transactionUrl + query).then((response) => {
            if (!response.ok) {
                console.error('Failed to send transaction data to FindMine');
            }
        });
    });
    
    function _getFindMineCookie() {
        var fmCookie = document.cookie.match('(^|;) ?_fmSession=([^;]*)(;|$)');
        return fmCookie ? fmCookie[2] : null;
    }
    
  5. Edit the above code snippet to add your FindMine Application ID and, if needed, remove unnecessary fields called out in the code

  6. Click Save at the top of the page, then click Connect to enable the Custom Pixel on the storefront

  7. Place some test transactions and validate their receipt and structure with FindMine; the transactions are sent from the Thank You page when checkout is complete