Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add JavaScript in Shopify public app

Im developing a Shopify public app using Ruby on Rails. I want disaply some information in all the store front pages. The official documents only explains about the admin panel modifications. How can I access the store front? And where I should add the scripts, I mean in which controller?

Actually Im a PHP Developer. Im new to Shopify and also Ruby on Rails. Im trying to develop a shopify public app which will show product related information in all pages (front-end). I followed shopify's tutorial first, and created a hello world like app which displays products list in admin side. But I really cant find anything that make changes in the store frontend.

So please help me that how to make changes in frontend. Also I want to get the current user information and product details (if it is a product view page).

like image 358
Vicky M Avatar asked Oct 28 '25 01:10

Vicky M


1 Answers

We can use config.scripttags to load javascripts in shopify store front pages. The syntax will be as follows:

config.scripttags = [
  {event:'onload', src: 'https://domainname.com/path_to_script.js'},
]

You should add this code in the shopify_app Gem initializer file, which can be found in

config/initializers/shopify_app.rb

Hope this will help someone..!

like image 96
Vicky M Avatar answered Oct 30 '25 15:10

Vicky M



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!