Ad

How To Add JavaScript In Shopify Public App

- 1 answer

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).

Ad

Answer

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..!

Ad
source: stackoverflow.com
Ad