Forums / General Questions / script for thank you page

script for thank you page

Views: 2,317

Results 1 to 20 of 23
11 Feb 2016, 2:06 PM
#1
100asa avatar

100asa

Totally Zenned

Join Date:
Oct 2006
Location:
Italy
Posts:
636
Plugin Contributions:
0

script for thank you page

A service for trusted reviews have asked me to add this code

<script type="text/javascript" src="https://tracking.trovaprezzi.it/javascripts/tracking.min.js" async="true"></script>

  <script type="text/javascript">
      window._tt = window._tt || [];
      window._tt.push({ event: "setAccount", id: /* keymerchant */ });
      window._tt.push({ event: "setOrderId", order_id: /* idorder */ });
      window._tt.push({ event: "setEmail", email: /* emailcucstomer */ });
      window._tt.push({ event: "addItem", sku: /* sku */, product_name: /* product_name */ });
      window._tt.push({ event: "orderSubmit"});
  </script>

They asked me to put this code into thank you page.
Where can I put this code into zencart?
Many thanks to who help me.

11 Feb 2016, 3:00 PM
#2
store_support avatar

store_support

New Zenner

Join Date:
Apr 2014
Location:
Polska
Posts:
20
Plugin Contributions:
0

Re: script for thank you page

Hi
You can add it at the bottom of includes/templates/yourtemplate/templates/tpl_checkout_success.php file, just remember to replace these tags /* keymerchant */ ... with proper zencart variables.

11 Feb 2016, 3:03 PM
#3
lat9 avatar

lat9

Administrator

Join Date:
Sep 2009
Location:
Stuart, FL
Posts:
14,109
Plugin Contributions:
56

Re: script for thank you page

Create the file /includes/modules/pages/checkout_success/jscript_tracking.php that contains:

<?php
//-Add the tracking script only for the checkout_success page
?>
  <script type="text/javascript" src="https://tracking.trovaprezzi.it/javascripts/tracking.min.js" async="true"></script>

  <script type="text/javascript">
      window._tt = window._tt || [];
      window._tt.push({ event: "setAccount", id: /* keymerchant */ });
      window._tt.push({ event: "setOrderId", order_id: /* idorder */ });
      window._tt.push({ event: "setEmail", email: /* emailcucstomer */ });
      window._tt.push({ event: "addItem", sku: /* sku */, product_name: /* product_name */ });
      window._tt.push({ event: "orderSubmit"});
  </script> 
11 Feb 2016, 3:06 PM
#4
100asa avatar

100asa

Totally Zenned

Join Date:
Oct 2006
Location:
Italy
Posts:
636
Plugin Contributions:
0

Re: script for thank you page

Ok, thanks. But how can retrieve the orderID, custoemr email and product_name (sku)?

11 Feb 2016, 5:08 PM
#6
lat9 avatar

lat9

Administrator

Join Date:
Sep 2009
Location:
Stuart, FL
Posts:
14,109
Plugin Contributions:
56

Re: script for thank you page

That will need a bit more processing, similar to:

<?php
//-Add the tracking script only for the checkout_success page
$customer_email_info = $db->Execute ("SELECT customers_email_address FROM " . TABLE_CUSTOMERS . " WHERE customers_id = " . (int)$_SESSION['customers_id'] . " LIMIT 1");
if (!$customer_email_info->EOF) {
  $customers_email_address = $customer_email_info->fields['customers_email_address'];
?>
  <script type="text/javascript" src="https://tracking.trovaprezzi.it/javascripts/tracking.min.js" async="true"></script>

  <script type="text/javascript">
      window._tt = window._tt || [];
      window._tt.push({ event: "setAccount", [B]id[/B]: /* keymerchant */ });
      window._tt.push({ event: "setOrderId", <?php echo $order_id; ?>: /* idorder */ });
      window._tt.push({ event: "setEmail", "<?php echo $customers_email_address; ?>": /* emailcucstomer */ });
<?php
  foreach ($orders->products as $current_product) {
?>
      window._tt.push({ event: "addItem", "<?php echo $current_product['model']; ?>": /* sku */, "<?php echo $current_product['name']; ?>": /* product_name */ });
<?php
  }
?>
      window._tt.push({ event: "orderSubmit"});
  </script>
<?php
}

Please note that the item-related output will most likely fail if you have a product that doesn't have a model number. You'll need to "hardcode" whatever your merchant account key is into the **id **spot; make sure to enclose it in quotes, e.g. "XYZZY-001".

11 Feb 2016, 5:29 PM
#7
100asa avatar

100asa

Totally Zenned

Join Date:
Oct 2006
Location:
Italy
Posts:
636
Plugin Contributions:
0

Re: script for thank you page

sorry, but the variables to substitute with zencart values are enclosed into /* /
as /
idorder / and / emailcustomer */ .....

11 Feb 2016, 5:46 PM
#8
lat9 avatar

lat9

Administrator

Join Date:
Sep 2009
Location:
Stuart, FL
Posts:
14,109
Plugin Contributions:
56

Re: script for thank you page

How's this:

<?php
//-Add the tracking script only for the checkout_success page
$customer_email_info = $db->Execute ("SELECT customers_email_address FROM " . TABLE_CUSTOMERS . " WHERE customers_id = " . (int)$_SESSION['customers_id'] . " LIMIT 1");
if (!$customer_email_info->EOF) {
  $customers_email_address = $customer_email_info->fields['customers_email_address'];
?>
  <script type="text/javascript" src="https://tracking.trovaprezzi.it/javascripts/tracking.min.js" async="true"></script>

  <script type="text/javascript">
      window._tt = window._tt || [];
      window._tt.push({ event: "setAccount", id: /* keymerchant */ });
      window._tt.push({ event: "setOrderId", order_id: <?php echo $order_id; ?> /* idorder */ });
      window._tt.push({ event: "setEmail", email: "<?php echo $customers_email_address; ?>" /* emailcucstomer */ });
<?php
  foreach ($orders->products as $current_product) {
?>
      window._tt.push({ event: "addItem", sku: "<?php echo $current_product['model']; ?>" /* sku */, product_name: "<?php echo $current_product['name']; ?>" /* product_name */ });
<?php
  }
?>
      window._tt.push({ event: "orderSubmit"});
  </script>
<?php
}
11 Feb 2016, 6:13 PM
#9
100asa avatar

100asa

Totally Zenned

Join Date:
Oct 2006
Location:
Italy
Posts:
636
Plugin Contributions:
0

Re: script for thank you page

Thank you so much for your help!
I wait for the mechant-key from Trovaprezzi search engine, and then let you know if your script works well.

12 Feb 2016, 2:08 PM
#10
100asa avatar

100asa

Totally Zenned

Join Date:
Oct 2006
Location:
Italy
Posts:
636
Plugin Contributions:
0

Re: script for thank you page

<?php
//-Add the tracking script only for the checkout_success page
$customer_email_info = $db->Execute ("SELECT customers_email_address FROM " . TABLE_CUSTOMERS . " WHERE customers_id = " . (int)$_SESSION['customers_id'] . " LIMIT 1");
if (!$customer_email_info->EOF) {
  $customers_email_address = $customer_email_info->fields['customers_email_address'];
?>
  <script type="text/javascript" src="https://tracking.trovaprezzi.it/javascripts/tracking.min.js" async="true"></script>

  <script type="text/javascript">
      window._tt = window._tt || [];
      window._tt.push({ event: "setAccount", id: "RMUnJ1SUw1" });
      window._tt.push({ event: "setOrderId", order_id: "<?php echo $order_id; ?>" });
      window._tt.push({ event: "setEmail", email: "<?php echo $customers_email_address; ?>"  });
<?php
  foreach ($orders->products as $current_product) {
?>
      window._tt.push({ event: "addItem", sku: "<?php echo $current_product['model']; ?>" , product_name: "<?php echo $current_product['name']; ?>" });
<?php
  }
?>
      window._tt.push({ event: "orderSubmit"});
  </script>
<?php
}

but nothing happens

12 Feb 2016, 2:13 PM
#11
lat9 avatar

lat9

Administrator

Join Date:
Sep 2009
Location:
Stuart, FL
Posts:
14,109
Plugin Contributions:
56

Re: script for thank you page

So, you created the separate file (/includes/modules/pages/checkout_success/jscript_tracking.php) with the contents above. Now, on the checkout_success page, when "nothing happens" ... what does that mean?

12 Feb 2016, 2:22 PM
#12
lat9 avatar

lat9

Administrator

Join Date:
Sep 2009
Location:
Stuart, FL
Posts:
14,109
Plugin Contributions:
56

Re: script for thank you page

OK, after re-reviewing the header processing for the checkout_success page, I was using the wrong variables, having incorrectly assumed that an order-class element had been created. Give the following a go:

<?php
//-Add the tracking script only for the checkout_success page
$customer_email_info = $db->Execute ("SELECT customers_email_address FROM " . TABLE_CUSTOMERS . " WHERE customers_id = " . (int)$_SESSION['customers_id'] . " LIMIT 1");
if (!$customer_email_info->EOF) {
  $customers_email_address = $customer_email_info->fields['customers_email_address'];
?>
  <script type="text/javascript" src="https://tracking.trovaprezzi.it/javascripts/tracking.min.js" async="true"></script>

  <script type="text/javascript">
      window._tt = window._tt || [];
      window._tt.push({ event: "setAccount", [B]id[/B]: /* keymerchant */ });
      window._tt.push({ event: "setOrderId", order_id: <?php echo $order_id; ?> /* idorder */ });
      window._tt.push({ event: "setEmail", email: "<?php echo $customers_email_address; ?>" /* emailcucstomer */ });
<?php
  $products_info = $db->Execute ("SELECT products_model, products_name FROM " . TABLE_ORDERS_PRODUCTS . " WHERE orders_id = $order_id");
  while (!$products_info->EOF) {
?>
      window._tt.push({ event: "addItem", sku: "<?php echo $products_info->fields['products_model']; ?>" /* sku */, product_name: "<?php echo $products_info->fields['products_name']; ?>" /* product_name */ });
<?php
    $products_info->MoveNext ();
  }
?>
      window._tt.push({ event: "orderSubmit"});
  </script>
<?php
}
12 Feb 2016, 2:28 PM
#13
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

Re: script for thank you page

Part of why lat9 has asked that question s that the script provided basically gathers data together and provides it back to the "company" to provide additional tracking information. There are results that should be able to be reviewed, but the "nothing happens" description does not clearly identify 1) action taken to validate operation or 2) results of that action.

ZC Installation/Maintenance Support <- Site
Contribution for contributions welcome...

12 Feb 2016, 5:34 PM
#14
100asa avatar

100asa

Totally Zenned

Join Date:
Oct 2006
Location:
Italy
Posts:
636
Plugin Contributions:
0

Re: script for thank you page

the example script equipped by Trovaprezzi need to track shop by customer and invites to add reviews on trovaprezzi website
Here you can find a guide to installation: https://tracking.trovaprezzi.it/guida.html
So, the script edited by lat9 don't start, so if I open the ceckout_success source page, there is no trace of the code.

12 Feb 2016, 6:42 PM
#15
lat9 avatar

lat9

Administrator

Join Date:
Sep 2009
Location:
Stuart, FL
Posts:
14,109
Plugin Contributions:
56

Re: script for thank you page

Does your store's template already load a version of jQuery >= 1.4?

13 Feb 2016, 4:59 PM
#16
100asa avatar

100asa

Totally Zenned

Join Date:
Oct 2006
Location:
Italy
Posts:
636
Plugin Contributions:
0

Re: script for thank you page

yes, sure!

17 Feb 2016, 8:38 AM
#17
100asa avatar

100asa

Totally Zenned

Join Date:
Oct 2006
Location:
Italy
Posts:
636
Plugin Contributions:
0

Re: script for thank you page

No new suggestions?

17 Feb 2016, 10:47 AM
#18
store_support avatar

store_support

New Zenner

Join Date:
Apr 2014
Location:
Polska
Posts:
20
Plugin Contributions:
0

Re: script for thank you page

Hi again
I did checked the code at vanila zen 154 and seems there are some typos so fixed version below

<?php
//-Add the tracking script only for the checkout_success page
$customer_email_info = $db->Execute ("SELECT customers_email_address FROM " . TABLE_CUSTOMERS . " WHERE customers_id = " . (int)$_SESSION['customer_id'] . " LIMIT 1");
if (!$customer_email_info->EOF) {
  $customers_email_address = $customer_email_info->fields['customers_email_address'];

  $outputCode = '';
  $outputCode .=' 
  <script type="text/javascript" src="https://tracking.trovaprezzi.it/javascripts/tracking.min.js" async="true"></script>
  <script type="text/javascript">
      window._tt = window._tt || [];
      window._tt.push({ event: "setAccount", id: /* keymerchant */ });
      window._tt.push({ event: "setOrderId", order_id: "'.$orders_id.'"});
      window._tt.push({ event: "setEmail", email: "'.$customers_email_address.'"});';

  $products_info = $db->Execute ("SELECT products_model, products_name FROM " . TABLE_ORDERS_PRODUCTS . " WHERE orders_id = $orders_id");
  while (!$products_info->EOF) {
  $outputCode .='
      window._tt.push({ event: "addItem", sku: "'.$products_info->fields['products_model'].'" , product_name: "'.$products_info->fields['products_name'].'" });';

    $products_info->MoveNext ();
  }
  $outputCode .='
  window._tt.push({ event: "orderSubmit"});
  </script>';
 echo $outputCode;
}
?>

I have added it at the bottom of includes/templates/yourtemplate/templates/tpl_checkout_success.php file, before closing </div> tag (I know this is dirty hardcoded way but it works so why bother if it is only single customisation)

Remember to replace this tag /* keymerchant */ with your code.

After this it shows up in source at checkout success page.
Let us know how it works.

Regards
Tomek

17 Feb 2016, 11:05 AM
#19
100asa avatar

100asa

Totally Zenned

Join Date:
Oct 2006
Location:
Italy
Posts:
636
Plugin Contributions:
0

Re: script for thank you page

Thank you so much @store-support: now my includes/templates/mytemplate/templates/tpl_ceckout_success_default.php is this

<?php
/**
 * Page Template
 *
 * Loaded automatically by index.php?main_page=checkout_success.<br />
 * Displays confirmation details after order has been successfully processed.
 *
 * @package templateSystem
 * @copyright Copyright 2003-2010 Zen Cart Development Team
 * @copyright Portions Copyright 2003 osCommerce
 * @license http://www.zen-cart.com/license/2_0.txt GNU Public License V2.0
 * @version $Id: tpl_checkout_success_default.php 16435 2010-05-28 09:34:32Z drbyte $
 */
?>
<div class="centerColumn" id="checkoutSuccess">
	<header>
    	<h1 id="checkoutSuccessHeading"><?php echo HEADING_TITLE; ?></h1>
    </header>
    <div class="alert alert-success alert-dismissable">
    	<?php echo TEXT_THANKS_FOR_SHOPPING; ?>
		<div id="checkoutSuccessOrderNumber"><?php echo TEXT_YOUR_ORDER_NUMBER . $zv_orders_id; ?></div>
    </div>
    <!--bof logoff-->
    <div class="alert alert-info alert-dismissable">
		<?php
			if (isset($_SESSION['customer_guest_id'])) {
				echo TEXT_CHECKOUT_LOGOFF_GUEST;
			} elseif (isset($_SESSION['customer_id'])) {
				echo TEXT_CHECKOUT_LOGOFF_CUSTOMER;
			}
		?>
        <div class="buttonRow forward">
        	<a href="<?php echo zen_href_link(FILENAME_LOGOFF, '', 'SSL'); ?>"><?php echo zen_image_button(BUTTON_IMAGE_LOG_OFF , BUTTON_LOG_OFF_ALT); ?>
            </a>
        </div>
	</div>
    <div class="alert alert-info alert-dismissable">
    	<?php echo TEXT_SEE_ORDERS .'<br/>'. TEXT_CONTACT_STORE_OWNER;?>
	</div>
    <!--bof -gift certificate- send or spend box-->
	<?php
    // only show when there is a GV balance
      if ($customer_has_gv_balance ) {
    ?>
	<div id="sendSpendWrapper">
		<?php require($template->get_template_dir('tpl_modules_send_or_spend.php',DIR_WS_TEMPLATE, $current_page_base,'templates'). '/tpl_modules_send_or_spend.php'); ?>
	</div>
	<?php
      }
    ?>
	<!--eof -gift certificate- send or spend box-->
	<!--eof logoff-->
	<div class="content">
		<?php if (DEFINE_CHECKOUT_SUCCESS_STATUS >= 1 and DEFINE_CHECKOUT_SUCCESS_STATUS <= 2) { ?>
			<div id="checkoutSuccessMainContent">
				<?php
				/**
				 * require the html_defined text for checkout success
				 */
				  require($define_page);
				?>
			</div>
		<?php } ?>
		<!-- bof payment-method-alerts -->
		<?php
        	if (isset($_SESSION['payment_method_messages']) && $_SESSION['payment_method_messages'] != '') {
        ?>
            <div>
                <?php echo $_SESSION['payment_method_messages']; ?>
            </div>
		<?php
        }
        ?>
        <!-- eof payment-method-alerts -->
	</div>
		<?php
        /**
         * The following creates a list of checkboxes for the customer to select if they wish to be included in product-notification
         * announcements related to products they've just purchased.
         **/
            if ($flag_show_products_notification == true) {
        ?>
	<div class="content">
		<div id="csNotifications">
			<h4><?php echo TEXT_NOTIFY_PRODUCTS; ?></h4>
			<?php echo zen_draw_form('order', zen_href_link(FILENAME_CHECKOUT_SUCCESS, 'action=update', 'SSL')); ?>
			<?php foreach ($notificationsArray as $notifications) { ?>
            	<?php echo zen_draw_checkbox_field('notify[]', $notifications['products_id'], true, 'id="notify-' . $notifications['counter'] . '"') ;?>
            	<label class="checkboxLabel" for="<?php echo 'notify-' . $notifications['counter']; ?>">
					<?php echo $notifications['products_name']; ?>
                </label>
            	<br />
            <?php } ?>
            <div class="buttonRow forward"><?php echo zen_image_submit(BUTTON_IMAGE_UPDATE, BUTTON_UPDATE_ALT); ?></div>
            </form>
		</div>
	</div>
            <?php
                }
            ?>
	<!--eof -product notifications box-->
	<!--bof -product downloads module-->
	<?php
      if (DOWNLOAD_ENABLED == 'true') require($template->get_template_dir('tpl_modules_downloads.php',DIR_WS_TEMPLATE, $current_page_base,'templates'). '/tpl_modules_downloads.php');
    ?>
    <!--eof -product downloads module-->
</div>

<?php if (MODULE_BARCODE_ORDERS_SWITCH == 'true') { ?>
<div id="checkoutSuccessOrdersBarcode">
  <fieldset>
    <legend><?php echo TABLE_HEADING_ORDERS_BARCODE; ?></legend>
    <?php echo TEXT_ORDERS_BARCODE; ?><br />
    <?php echo '<img src="' . DIR_WS_CATALOG . 'barcode/barcode.php?code=' . $_SESSION['orders_barcode'] . '&scale=' . (int)MODULE_BARCODE_SCALE . '"></img>'; ?>
  </fieldset> 

<?php
//-Add the tracking script only for the checkout_success page
$customer_email_info = $db->Execute ("SELECT customers_email_address FROM " . TABLE_CUSTOMERS . " WHERE customers_id = " . (int)$_SESSION['customer_id'] . " LIMIT 1");
if (!$customer_email_info->EOF) {
$customers_email_address = $customer_email_info->fields['customers_email_address'];

$outputCode = '';
$outputCode .='
<script type="text/javascript" src="https://tracking.trovaprezzi.it/javascripts/tracking.min.js" async="true"></script>
<script type="text/javascript">
window._tt = window._tt || [];
window._tt.push({ event: "setAccount", id: "xxxxx" });
window._tt.push({ event: "setOrderId", order_id: "'.$orders_id.'"});
window._tt.push({ event: "setEmail", email: "'.$customers_email_address.'"});';

$products_info = $db->Execute ("SELECT products_model, products_name FROM " . TABLE_ORDERS_PRODUCTS . " WHERE orders_id = $orders_id");
while (!$products_info->EOF) {
$outputCode .='
window._tt.push({ event: "addItem", sku: "'.$products_info->fields['products_model'].'" , product_name: "'.$products_info->fields['products_name'].'" });';

$products_info->MoveNext ();
}
$outputCode .='
window._tt.push({ event: "orderSubmit"});
</script>';
echo $outputCode;
}
?>

</div>
<?php } ?>

but nothing appear, and on ceckout_success source page nothing found as "trovaprezzi"

17 Feb 2016, 11:18 AM
#20
store_support avatar

store_support

New Zenner

Join Date:
Apr 2014
Location:
Polska
Posts:
20
Plugin Contributions:
0

Re: script for thank you page

Hi
You need to add it into tpl_checkout_success_default.php (typo?) and closing <?php } ?> should be before </div>, then refresh success page and check source code at bottom.

Also are You sure you are adding it into proper template?