[Skip to main content](#vessel-content)

#   Analytics tag begin checkout

##

- **[marchela-apostolova](/forum/user/58393-marchela-apostolova "View marchela-apostolova's Profile")**
- [![marchela-apostolova's Avatar](https://www.hikashop.com/media/kunena/core/svg/person.svg)](/forum/user/58393-marchela-apostolova "View marchela-apostolova's Profile") Topic Author
- [ Offline](/forum/user/58393-marchela-apostolova)

Less More

- Posts: 14
- Thank you received: 1
-
-

5 years 9 months ago [\#328373](#328373) by [marchela-apostolova](/forum/user/58393-marchela-apostolova "View marchela-apostolova's Profile")  *[Analytics tag begin checkout](/forum/27-checkout/901688-analytics-tag-begin-checkout#328373 "-- HikaShop version -- : 4.4.0  Hello,  I try to create marker in Analytics in the following file show&#95;block&#95;cart.php  Here is the code:  For products without Characteristics, everything works fine.  For products with Characteristics: in the script, there is the selected variant from the shopping cart + the main product with 0 quantity (which is not in the shopping cart).  Can you help me with this issue?  Best regards!")* was created by *[marchela-apostolova](/forum/user/58393-marchela-apostolova "View marchela-apostolova's Profile")*

-- HikaShop version -- : 4.4.0

Hello,

I try to create marker in Analytics in the following file show_block_cart.php

Here is the code: Code:

gtag('event', 'begin_checkout', { "items": [ &lt;?php $count = count($cart-&gt;products); ?&gt; &lt;?php foreach($cart-&gt;products as $i =&gt; $product){ ?&gt; { "id": "&lt;?php echo $product-&gt;product_id; ?&gt;", "name": "&lt;?php echo strip_tags($product-&gt;product_name); ?&gt;", "quantity": &lt;?php echo $product-&gt;cart_product_quantity; ?&gt;, "price": '&lt;?php echo $product-&gt;prices[0]-&gt;price_value; ?&gt;' }&lt;?php if ($i &gt; $count - 1) echo ","; ?&gt; &lt;?php $k = 1-$k; } ?&gt; ], "coupon": "&lt;?php echo $cart-&gt;coupon-&gt;discount_value;?&gt;" });

For products without Characteristics, everything works fine.

For products with Characteristics: in the script, there is the selected variant from the shopping cart + the main product with 0 quantity (which is not in the shopping cart). Code:

gtag('event', 'begin_checkout', { "items": [ { "id": "81", "name": "Dress color: black: S", "quantity": 1, "price": '29' }, { "id": "13", "name": "Bag", "quantity": 1, "price": '28' }, { "id": "80", "name": "Dress color: black", "quantity": 0, "price": '29.00000' } ], "coupon": "5.7" });

Can you help me with this issue?

Best regards!

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzI3LWNoZWNrb3V0LzkwMTY4OC1hbmFseXRpY3MtdGFnLWJlZ2luLWNoZWNrb3V0P3RtcGw9bWFya2Rvd24=) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[nicolas](/forum/user/63-nicolas "View nicolas's Profile")**
- [![nicolas's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar63.png?1793428657)](/forum/user/63-nicolas "View nicolas's Profile")
- [ Offline](/forum/user/63-nicolas)

Less More

- Posts: 86541
- Thank you received: 14304
-
-

5 years 9 months ago [\#328386](#328386) by [nicolas](/forum/user/63-nicolas "View nicolas's Profile")  Replied by *[nicolas](/forum/user/63-nicolas "View nicolas's Profile")* on topic *[Analytics tag begin checkout](/forum/27-checkout/901688-analytics-tag-begin-checkout#328386 "-- HikaShop version -- : 4.4.0  Hello,  I try to create marker in Analytics in the following file show&#95;block&#95;cart.php  Here is the code:  For products without Characteristics, everything works fine.  For products with Characteristics: in the script, there is the selected variant from the shopping cart + the main product with 0 quantity (which is not in the shopping cart).  Can you help me with this issue?  Best regards!")*

Hi,

You just need to skip the products with a quantity of 0 with such line of code at the beginning of your foreach:
if(empty($product-&gt;cart_product_quantity)) continue;

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzI3LWNoZWNrb3V0LzkwMTY4OC1hbmFseXRpY3MtdGFnLWJlZ2luLWNoZWNrb3V0P3RtcGw9bWFya2Rvd24=) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[marchela-apostolova](/forum/user/58393-marchela-apostolova "View marchela-apostolova's Profile")**
- [![marchela-apostolova's Avatar](https://www.hikashop.com/media/kunena/core/svg/person.svg)](/forum/user/58393-marchela-apostolova "View marchela-apostolova's Profile") Topic Author
- [ Offline](/forum/user/58393-marchela-apostolova)

Less More

- Posts: 14
- Thank you received: 1
-
-

5 years 9 months ago [\#328506](#328506) by [marchela-apostolova](/forum/user/58393-marchela-apostolova "View marchela-apostolova's Profile")  Replied by *[marchela-apostolova](/forum/user/58393-marchela-apostolova "View marchela-apostolova's Profile")* on topic *[Analytics tag begin checkout](/forum/27-checkout/901688-analytics-tag-begin-checkout#328506 "-- HikaShop version -- : 4.4.0  Hello,  I try to create marker in Analytics in the following file show&#95;block&#95;cart.php  Here is the code:  For products without Characteristics, everything works fine.  For products with Characteristics: in the script, there is the selected variant from the shopping cart + the main product with 0 quantity (which is not in the shopping cart).  Can you help me with this issue?  Best regards!")*

Thank you so much, Nicolas!

Probably in the shoppinng cart there is information for the main product, even if it's not visualized there.

Now it worked that way, but I seem to have problem with the product counting: at the end of the product list after the last product again there is , (comma).

Probably it still counts the main products as well with 0 quantity. Code:

gtag('event', 'begin_checkout', { "items": [ { "id": "81", "name": "Dress color: black: S", "quantity": 1, "price": '29' }, { "id": "13", "name": "Bag", "quantity": 1, "price": '28' }, ], "coupon": "5.7" });

Do you have any idea how can I fix this? 

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzI3LWNoZWNrb3V0LzkwMTY4OC1hbmFseXRpY3MtdGFnLWJlZ2luLWNoZWNrb3V0P3RtcGw9bWFya2Rvd24=) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[nicolas](/forum/user/63-nicolas "View nicolas's Profile")**
- [![nicolas's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar63.png?1793428657)](/forum/user/63-nicolas "View nicolas's Profile")
- [ Offline](/forum/user/63-nicolas)

Less More

- Posts: 86541
- Thank you received: 14304
-
-

5 years 9 months ago -  5 years 9 months ago [\#328513](#328513) by [nicolas](/forum/user/63-nicolas "View nicolas's Profile")  Replied by *[nicolas](/forum/user/63-nicolas "View nicolas's Profile")* on topic *[Analytics tag begin checkout](/forum/27-checkout/901688-analytics-tag-begin-checkout#328513 "-- HikaShop version -- : 4.4.0  Hello,  I try to create marker in Analytics in the following file show&#95;block&#95;cart.php  Here is the code:  For products without Characteristics, everything works fine.  For products with Characteristics: in the script, there is the selected variant from the shopping cart + the main product with 0 quantity (which is not in the shopping cart).  Can you help me with this issue?  Best regards!")*

Hi,

Well, you can't rely on $count. But the solution to your issue is PHP coding.
There are two ways to do it:
- instead of directly outputting the text, you could have an array where you would add the text for each product to be added.
And then, you would do a "echo implode(',', $array);" to output the text with a comma between each.
- instead of adding the comma at the end of the loop, you could add it at the beginning and just have a flag variable $first = true; before the loop. and in the loop you would have at the beginning : if($first) { $first = false; } else { echo ','; }

Last edit: 5 years 9 months ago by [nicolas](/forum/user/63-nicolas "View nicolas's Profile").

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzI3LWNoZWNrb3V0LzkwMTY4OC1hbmFseXRpY3MtdGFnLWJlZ2luLWNoZWNrb3V0P3RtcGw9bWFya2Rvd24=) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

Board Categories HikaShop Install &amp; Update Product &amp; Category Display Content Creation Sales and Orders Orders management Reports &amp; Statistics Customers Checkout Payment Methods Shipping Methods Import &amp; Export (CSV, XLS…) Specific Features Affilation Taxes Wishlist Vote Carousel &amp; Slider Mass Actions Filters &amp; Search Discount &amp; Coupon Feature Request Integrations Showcase General Talk about HikaShop Development HikaShop 3.0 Beta Translation Commercial Jobs HikaShop Components HikaMarket Market: Feature requests Market: How to? Market: Bug Report HikaSerial General talk about HikaSerial Serial: Bug Report Serial: How to? Support en Français de HikaSerial (French Support) HikaSubscription HikaAuction Auction: Feature requests Auction: How to? Auction: Bug report Hikashop around the world Support en Français (French Support) Russian FAQ. Курс выживания с Hikashop. Частые вопросы и о Расширения Hikashop Наши сайты на Hikashop 日本語版サポート(Japanese Support) Thai German Archives Bug Report How to?

[](/forum/topics/feed/mode-topics?format=feed&type=rss)

Time to create page: 0.048 seconds

[Powered by](/forum/credits) [Kunena Forum](https://www.kunena.org)
