Pinterest Integration

  • Posts: 246
  • Thank you received: 2
  • Hikashop Business Hikashop Essential
2 years 8 months ago #340206

-- url of the page with the problem -- : www.beeswaxcandleshop.com/store.html
-- HikaShop version -- : 4.5.0
-- Joomla version -- : 3.10.6
-- PHP version -- : 7.4.28
-- Browser(s) name and version -- : chrome

I am working to integrate Pinterest and Hikashop. I have added their base code to the head of the site just fine. Now I need to add "add to cart", "checkout" and "page visit" to the site. I THINK I need to add it to each product page. Howe do I add script to each product page?

Please Log in or Create an account to join the conversation.

  • Posts: 82863
  • Thank you received: 13372
  • MODERATOR
2 years 8 months ago #340211

Hi,

Go in the menu Display>Views of HikaShop. There edit the file product / show for your frontend template and you can add your javascript in there.

The following user(s) said Thank You: bigfoot

Please Log in or Create an account to join the conversation.

  • Posts: 246
  • Thank you received: 2
  • Hikashop Business Hikashop Essential
2 years 8 months ago #340247

Thank you - It worked fine and the code is in all of the hikashop product files - however I will need to put code into each separate product files. I am trying to use "sourceror" and it works fine in a non hikashop article but when I use it in a hikashop product description article, all the "code" parts gets stripped out after saving and refreshing. Is there any setting in hikashop to change this?

Please Log in or Create an account to join the conversation.

  • Posts: 82863
  • Thank you received: 13372
  • MODERATOR
2 years 8 months ago #340250

Hi,

I don't think there is anything in HikaShop which does that for the product description. It's probably your HTML editor.
In the HikaShop configuration, you can change the "editor" setting to "none" to get a normal textarea instead of the HTML editor. That way you'll be able to check if it works like that, which would confirm it comes from the HTML editor, and maybe it has a setting to toggle to allow for that.
Alternatively, you can also create a custom field of the table "product" with ti's "input filtering" setting turned off via the menu Display>custom fields to add your code, and then in the product / show view file, you can use such code:
<?php echo $this->element->xxx; ?>
where xxx is the column name of the custom field.

Please Log in or Create an account to join the conversation.

  • Posts: 246
  • Thank you received: 2
  • Hikashop Business Hikashop Essential
2 years 8 months ago #340252

Thank you - It worked fine!

Please Log in or Create an account to join the conversation.

  • Posts: 246
  • Thank you received: 2
  • Hikashop Business Hikashop Essential
2 years 8 months ago #340336

Back with another quick similar question. I have two more pieces of code to insert in "add to cart" and "checkout". So it triggers when a customer from pinterest checks out.

I have added them to:
"cart / showcart.php" and "checkout / show.php" -- I do not think it is working correctly and cannot see them in source file.

Is this the best spot?


"sample"

<script>
pintrk('track', 'checkout', {
value: 100,
order_quantity: 1,
currency: 'USD',
line_items: [
{
product_id: {{ product.id }}
}
]
});
</script>

Last edit: 2 years 8 months ago by nicolas.

Please Log in or Create an account to join the conversation.

  • Posts: 82863
  • Thank you received: 13372
  • MODERATOR
2 years 8 months ago #340347

Hi,

If you want to add javascript code on the checkout, you can indeed add it in the checkout / show view file.
I actually do see your javascript code on the checkout page on your website:
i.imgur.com/IDJwjCY.png

The following user(s) said Thank You: bigfoot

Please Log in or Create an account to join the conversation.

  • Posts: 246
  • Thank you received: 2
  • Hikashop Business Hikashop Essential
2 years 2 weeks ago #346300

Hello - I am back again and still working on Pinterest integration. I have added a custom field to add code and it is working. However it is on the bottom of the body and I need it on the bottom of the HEAD area. It would be a slightly different code for each product. Is there a way to have a custom field for each product IN THE HEAD AREA?

Please Log in or Create an account to join the conversation.

  • Posts: 82863
  • Thank you received: 13372
  • MODERATOR
2 years 2 weeks ago #346305

Hi,

You can. For that, instead of directly writing your Javascript code inside script tags, you want to use the addScriptDeclaration method of Joomla:
docs.joomla.org/Adding_JavaScript
This method will add the script tags around your JS code and will add all that to the bottom of the head tag of the page.

The following user(s) said Thank You: bigfoot

Please Log in or Create an account to join the conversation.

  • Posts: 246
  • Thank you received: 2
  • Hikashop Business Hikashop Essential
2 years 2 weeks ago #346306

Thank you - I will check it out. Where do I paste in the script - In my new extra field I made, or somewhere else? Thank you

Please Log in or Create an account to join the conversation.

  • Posts: 82863
  • Thank you received: 13372
  • MODERATOR
2 years 2 weeks ago #346308

Hi,

In a previous message ( www.hikashop.com/forum/integrations/9041...egration.html#340336 ), you said that you had added your javascript code to "cart / showcart.php" and "checkout / show.php".
So I was thinking you would use an addScriptDeclaration call in these.

The following user(s) said Thank You: bigfoot

Please Log in or Create an account to join the conversation.

  • Posts: 246
  • Thank you received: 2
  • Hikashop Business Hikashop Essential
2 years 2 weeks ago #346311

Hello - I am a bit confused, I do not write code - just do a lot of copy/paste. (and pinterest does not help a lot to get everything working)

I previously put this code (below)in "cart / showcart.php" page and it shows up at the bottom of page source just fine, but it needs to be in the head. So now I need to use the addScriptDeclaration as you suggested.

<script>
pintrk('track', 'addtocart', {
value: 10.00,
order_quantity: 1,
currency: 'USD'
});
</script>

I am not exactly sure how to implement it. Trying to learn a few new things - I found this below:


Inline JavaScript

Blocks of JavaScript code can be declared directly within a component or module's display template using the JDocument class' addScriptDeclaration method:
```
<?php
$document = JFactory::getDocument();
$document->addScriptDeclaration('
window.event("domready", function() {
alert("An inline JavaScript Declaration");
});
');
?>
```

Question1 - So I need to put this code in my "cart / showcart.php" page. Where do I put the script, Inside the brackets?

<?php
$document = JFactory::getDocument();
$document->addScriptDeclaration('
window.event("domready", function() {
alert("An inline JavaScript Declaration");
});
');
?
<script>
pintrk('track', 'addtocart', {
value: 10.00,
order_quantity: 1,
currency: 'USD'
});
</script>>

I am a bit lost here - or do I put it somewhere else in my template and point to it???
+++++++

Question 2 - Here is a script commonly used in pinterest:
<script>
pintrk('track', 'pagevisit', {
line_items: [
{
product_id: {{ product.id }}
}
]
});
</script>

This part:
"product_id: {{ product.id }}"
will this automatically pull my hikashop product id and use it ? - at one time I was thinking I had to add this code with my actual product id pasted in - such as "product_id: {{ lp_3cyl }}" - I think this is incorrect?

Last Question/comment - I do not see a lot of info about using Pinterest with Hikashop - lots of stuff with Shopify and other systems. I really would like to see Hikashop playing nice with Pinterest - It would add value to Hikashop and their users. If you have any other links regarding Pinterest integration, please let me know.

Thank you for answering all my uninformed questions.

Bill

Please Log in or Create an account to join the conversation.

  • Posts: 82863
  • Thank you received: 13372
  • MODERATOR
2 years 2 weeks ago #346314

Hi,

If you've added the code:

<script>
pintrk('track', 'addtocart', {
value: 10.00,
order_quantity: 1,
currency: 'USD'
});
</script>
somewhere on a Joomla website in a PHP file and you want that JS code to be in the header of the page, then you can replace it by :
$document = JFactory::getDocument();
$document->addScriptDeclaration("
pintrk('track', 'addtocart', {
value: 10.00,
order_quantity: 1,
currency: 'USD'
});
");
This won't replace dynamically the data from the the products on the page.

In order to track everything (products, carts, orders), it requires the development of a plugin with hundreds of lines of code, similarly to what we did with the GA4 and Matomo plugins on our marketplace.
It's possible, but it's not something I can do for you here and if you're not familiar with PHP, you won't be able to do it either.

The following user(s) said Thank You: bigfoot

Please Log in or Create an account to join the conversation.

  • Posts: 246
  • Thank you received: 2
  • Hikashop Business Hikashop Essential
2 years 2 weeks ago #346361

I added this code:
$document = JFactory::getDocument();
$document->addScriptDeclaration("
pintrk('track', 'addtocart', {
value: 10.00,
order_quantity: 1,
currency: 'USD'
});
");

to the bottom of this page:
www.beeswaxcandleshop.com/cart/checkout.html
Looking at the page source, I see it in the bottom of the body, but not in the head where I want it - Did I do something wrong?
(I must have - I am seeing this code in bottom of live checkout page - oops)

Last edit: 2 years 2 weeks ago by bigfoot. Reason: more info

Please Log in or Create an account to join the conversation.

  • Posts: 82863
  • Thank you received: 13372
  • MODERATOR
2 years 2 weeks ago #346367

Hi,

You need to add PHP tags around your PHP code:

<?php
$document = JFactory::getDocument();
$document->addScriptDeclaration("
pintrk('track', 'addtocart', {
value: 10.00,
order_quantity: 1,
currency: 'USD'
});
");
?>

Please Log in or Create an account to join the conversation.

  • Posts: 246
  • Thank you received: 2
  • Hikashop Business Hikashop Essential
2 years 1 week ago #346451

Thank you - that made it work. Another slight problem - I have a main pinterest tag added on ALL my pages through my template (shows at bottom of head) - Now the new script is showing above the main pinterest tag and it needs to be at the bottom - should I just put another copy of main pinterest tag in with the newly added one? The main pint tag needs to fire before the add to cart one.

Please Log in or Create an account to join the conversation.

  • Posts: 82863
  • Thank you received: 13372
  • MODERATOR
2 years 1 week ago #346456

Hi,

What you could do then is to use this code:

<?php
$document = JFactory::getDocument();
$document->addScriptDeclaration("
window.hikashop.ready(function(){
pintrk('track', 'addtocart', {
value: 10.00,
order_quantity: 1,
currency: 'USD'
});
});
");
?>
That way, the pintrk function will only be called once the page is fully loaded, and the JS of the template should have been executed by then.

Please Log in or Create an account to join the conversation.

Time to create page: 0.074 seconds
Powered by Kunena Forum