Q&A Conversion Tracking
Place the Conversion Tracking code on your theme’s success.phtml template file via ftp access.
Common Locations:
app/design/frontend/{your_vendor_name}/{your_theme_name}/Magento_Checkout/templates/success.phtml
app/design/frontend/{your_vendor_name}/{your_theme_name}/Magento_InventoryInStorePickupFrontend/templates/success.phtml
Note: From the source code below, please change the script src “https://YOUR-ACCOUNT-VALUE.services.answerbase.com/javascript/widget/conversion-tracking.min.js” into your conversion tracking script source which you’ll get from your answerbase dashboard > integration > conversion tracking.
Conversion Tracking Code:
<?php
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$order = $objectManager->create('Magento\Sales\Model\Order')->loadByIncrementId($successBlock->getOrderId());
$orderItems = $order->getAllVisibleItems();
$sale_total = $order->getGrandTotal();
$customer_email = $order->getCustomerEmail();
$ab_sku = '';
$ab_productId = '';
$ab_price = '';|
foreach ($orderItems as $item) {
$productSku = $item->getSku();
$productSku = str_replace('"', "", $productSku);
$productSku = str_replace("'", "", $productSku);
$productSku = str_replace(" ", "", $productSku);
$product_id = $item->getId();
$product_sku = $productSku;
$total = $item->getPrice();
$ab_sku .= $product_sku . ',';
$ab_productId .= $product_id . ',';
$ab_price .= $total . ',';
}
?>
<script src="https://YOUR-ACCOUNT-VALUE.services.answerbase.com/javascript/widget/conversion-tracking.min.js"
data-sale_total="<?= $sale_total ?>"
data-email="<?= $customer_email ?>"
data-sku="<?= rtrim($ab_sku,',') ?>"
data-productId="<?= rtrim($ab_productId,',') ?>"
data-price="<?= rtrim($ab_price,',') ?>">
</script>
Call to Action and Q&A Widget
Place the code on your theme’s detail_layout.phtml template file via ftp access.
Note: From the source code below, please change the sample script src of the call to action and Q&A widget into your own script src which you’ll get from your answerbase dashboard > integration > Q&A Widget.
Please enter a CSS selector for the ‘data-insert-after’ attribute of the call to action and Q&A widget. The CSS selector could be a class or Id of an html element on the product page. This will determine where you wanted to display the call to action and Q&A widget.
Location:
app/design/frontend/{your_vendor_name}/{your_theme_name}/Magento_Catalog/templates/product/view/detail_layout.phtml
Call to Action Widget Code
<script src="https://YOUR-ACCOUNT-VALUE.services.answerbase.com/javascript/widget/cta-widget.min.js"
data-insert-after="" defer>
</script>
Q&A Widget Code
The variables being used for these parameters data-product-external-id, data-product-sku, data-product-title, data-product-price, data-product-url, data-product-description, data-product-image-url will vary depending on the product template. You can modify the code according to your needs.
<script type="text/javascript" src="https://YOUR-ACCOUNT-VALUE.services.answerbase.com/javascript/widget/full-featured-widget.min.js"
data-product-external-id="<?= $_product->getId() ?>"
data-product-sku="<?= $prodSKU = str_replace('"', "", $_product->getSku()); $prodSKU = str_replace("'", "", $prodSKU); $prodSKU = str_replace(" ", "", $prodSKU); ?>"
data-product-title="<?= $prodName = str_replace('"', "''", $_product->getName()); ?>"
data-product-price="<?= number_format($_product->getFinalPrice(), 2, ".", ","); ?>"
data-product-url="<?= $_product->getProductUrl() ?>"
data-product-description="<?= preg_replace("/\s/", " ", $block->escapeHTML($_product->getDescription())) ?>"
data-product-image-url="<?= $block->getUrl('pub/media/catalog').'product'.$_product->getImage() ?>"
data-open-ask="expand"
data-show-question-details="true"
data-list-type="relevance"
data-show-content-allproducts="true"
data-insert-after="" defer>
</script>
The source code of getting the value for data-product-association-product-category parameter will vary depending on your product template and also on how you set up your categories. Here’s the sample code below on how to get the category id assigned to a product.
$categoryIDs = [];
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$product = $objectManager->get('Magento\Framework\Registry')->registry('current_product');
$categories = $product->getCategoryIds(); /*will return category ids array*/
foreach($categories as $category){
$cat = $objectManager->create('Magento\Catalog\Model\Category')->load($category);
//echo $cat->getName() . ' ' . $cat->getId() . ' ' . $cat->getPath() . '<br>'; // uncomment on debug
$getCategoryIDs = explode('/', $cat->getPath());
for($s=0; $s<sizeof($getCategoryIDs); $s++) {
array_push($categoryIDs, $getCategoryIDs[$s]);
}
}
//echo '<br>'; // uncomment on debug
$uniqueCategoryIDs = array_unique($categoryIDs); // remove duplicate ids
$resultCategoryIDs = array_values($uniqueCategoryIDs); // reindex values
Add this to your Q&A Widget Code:
data-product-association-product-category="<?= $resultCategoryIDs[3] ?>"
Sample value for the search parameter on the Q&A widget. The values that you'll populate within this parameter will let Answerbase know (1) what HTML element the content can be found within and (2) separated by a comma you'll let us know what the title of the content is. For example, if your information is contained within a <div> element with the class "product-details"....then you could define the value of this parameter in this format "[DIV-CLASS], [INFORMATION-TITLE]" and you may put ".product-details, Product Information".
data-on-page-search-elements="#description, Description; .data.item.content[id='mycustom.tab.low.price.gurantee'], Low Price Guarantee;
.data.item.content[id='mycustom.tab.shipping.policy'], Shipping Policy; .data.item.content[id='mycustom.tab.return.policy'], Return Policy"
See reference - https://help.answerbase.com/Article/2885257/Parameters-supported-for-the-Answerbase-Full-Featured-Widget
If you have any questions, please reach out to [email protected].