Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

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.

...

Code Block
<!-- 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=2Magento2.1' width='1' height='1'>
<script src='https://www.dwin1.com/19038.js' type='text/javascript' defer='defer'></script>
<!-- end ShareASale.com affiliate tracking -->

...

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.

...