Magento 2 Tracking Setup

ShareASale’s tracking for Magento involves two 'tags,' which are snippets of code installed in the success.phtml template file and in the Design configuration of Magento’s admin. The first tag is for tracking conversions (i.e. sales) and the second for assisting with Affiliate click attribution accuracy in certain browsers. Installation of both should be simply copy and paste of the code included herein.

Conversion Tracking Pixel Installation

Locate the success.phtml file on your server found at:
app/design/frontend/THEME/THEME_NAME/Magento_Checkout/templates/success.phtml

Replace [THEME] and [THEME_NAME] with your current Magento theme/template.

If the file doesn’t exist, instead edit the success.phtml file found at:
/vendor/magento/module-checkout/view/frontend/templates/success.phtml

Make a backup of the success.phtml file.

*Note: This is an important step since you are editing core Magento files.

 Find the end of the file, usually after the final close </div> tag around line 28:

Replace XXXXX in the script below with your ShareASale Merchant ID (Line 3).

Replace the !!!!!! in the code below with your Master Tag ID (Line 38).

For merchants in the Setup Wizard, you can find this within Step 4 (Tracking Code Installation).

For live merchants, you can find this by navigating to MY ACCOUNT > ACCOUNT DETAILS
Account Details: https://account.shareasale.com/m-account.cfm

If you cannot locate your Master Tag ID, or would like to verify that you have one, please submit a ticket to our ShareASale support staff.

<!-- begin ShareASale.com affiliate tracking --> <?php $merchantid = 'XXXXX'; $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $orderId = $block->getOrderId(); $order = $objectManager->create('Magento\Sales\Model\Order')->loadByIncrementId($orderId); $subtotal = $order->getSubtotal(); $discount = $order->getDiscountAmount(); $affiliateTotal = ($subtotal + $discount); $ordered_items = $order->getAllVisibleItems(); $skulist = ''; $pricelist = ''; $quantitylist = ''; $last_index = array_search(end($ordered_items), $ordered_items, true); foreach($ordered_items as $index => $item){ $delimiter = $index === $last_index ? '' : ','; $skulist .= $item->getSku() . $delimiter; $quantitylist .= ceil($item->getQtyOrdered()) . $delimiter; $pricelist .= ($item->getProduct()->getFinalPrice() - ($item->getDiscountAmount() / $item->getQtyOrdered())) . $delimiter; } $couponcodes = $order->getCouponCode(); $newcustomer = ''; $customer = $order->getCustomerId(); if($customer){ $orderCount = $objectManager ->create('\Magento\Sales\Model\ResourceModel\Order\CollectionFactory') ->create() ->addFieldToSelect('*') ->addFieldToFilter('customer_id', $customer) ->setOrder('created_at','desc') ->count(); $newcustomer = ($orderCount > 1 ? 0 : 1); } $currency = $order->getOrderCurrencyCode(); ?> <img id='_SHRSL_img_1' src='https://shareasale.com/sale.cfm?tracking=<?php echo $orderId ?>&amp;amount=<?php echo $affiliateTotal ?>&amp;transtype=sale&amp;merchantID=<?php echo $merchantid ?>&amp;couponcode=<?php echo $couponcodes ?>&amp;skulist=<?php echo $skulist ?>&amp;quantitylist=<?php echo $quantitylist ?>&amp;pricelist=<?php echo $pricelist ?>&amp;newcustomer=<?php echo $newcustomer ?>&amp;currency=<?php echo $currency ?>&amp;v=Magento2.1' width='1' height='1'> <script src='https://www.dwin1.com/!!!!!.js' type='text/javascript' defer='defer'></script> <!-- end ShareASale.com affiliate tracking -->

Copy and paste the modified script (with the correct Merchant ID) into the success.phtml file.

Master Tag Installation

Open your Magento store’s admin and click the 'Content' icon in the sidebar, then 'Configuration' option under the 'Design' header.

Click edit next to your global store view.

Scroll down to the 'HTML Head' section and click its name to expand it.

Find the 'Scripts and Style Sheets' section.

In this box, copy and paste the following script code underneath any existing possible code in the box.

<script src='https://www.dwin1.com/!!!!!.js' type='text/javascript' defer='defer'></script>

Make sure you click Save Configuration file button in the top right corner of the page.

Testing

Now that your tracking tags have been installed, we will need to test that everything is working as expected. To do this, we’ll simulate an Affiliate referred purchase by clicking a ShareASale test link and then running a purchase on your store. If the test is successful we’ll see a record appear in your ShareASale console, which we will VOID so that it doesn’t debit commissions from your account.

If you were emailed a link to this document, a test link may have been provided to you. If it wasn’t, you can obtain one from your account by clicking here.

NOTE: If you do not click the test link your order will not track.

The test link should direct you to your own store. Once there, please purchase any item in your store. Sometimes Merchants will have a test item worth $1.00 sale price, but above $0.00 minimum.

After the purchase is complete, navigate to www.shareasale.com in your browser and log into your account. Click Reports and then click Transaction Details from the drop-down menu.

Filter the report for Affiliate ID 178 using the panel on the left. The filtered view should now show your test purchase as an entry with today’s date.

If the order tracked successfully…

Your account is now ready to use ShareASale with your store. Please contact us at ShareASale@ShareASale.com for further information about:

  • Product specific commissions (offer different commissions by product)

  • New customer incentives (offer commission bonuses for new customers)

  • Exclusive coupon codes (used for tracking conversions without link clickthrough)

If the order does not show up in the Transaction Details Report…

Please verify that you have completed all of the steps as instructed. Common mistakes include not entering the correct Merchant ID in your tracking code and forgetting to click the test link.

If after verifying all of these steps your tracking still does not work please contact our support team at ShareASale@ShareASale.com.

Copyright ShareASale 2021