Skip to content
View lovebanane's full-sized avatar

Block or report lovebanane

Block user

Prevent this user from interacting with your repositories and sending you notifications. Learn more about blocking users.

You must be logged in to block users.

Maximum 250 characters. Please don't include any personal information such as legal names or email addresses. Markdown supported. This note will be visible to only you.
Report abuse

Contact GitHub support about this user’s behavior. Learn more about reporting abuse.

Report abuse
lovebanane/README.md

gtm_rails Build Status Gem Version git.legal

Simply embed Google Tag Manager container snippet into Rails application.

Installation

Add these lines to your application's Gemfile:

gem 'gtm_rails'

And then execute:

$ bundle install

Configuration

Create config/google_tag_manager.yml in your Rails application.

staging:
  foo: GTM-YourGtmId1
  bar: GTM-YourGtmId2
  baz: GTM-YourGtmId3
production:
  foo: GTM-YourGtmId4
  bar: GTM-YourGtmId5
  baz: GTM-YourGtmId6

The above is a sample. foo, bar, baz are arbitrary label names, and replacing GTM-XXXX with your container ID.

In view, use two helper methods.

  1. google_tag_manager_script_tag(label_name)
  2. google_tag_manager_noscript_tag(label_name)

These method arguments are a label name specified in config/google_tag_manager.yml.

First, following method as close to the opening <head> tag as possible on every page of your website.

<%= google_tag_manager_script_tag(:foo) %>

Google Tag Manager container snippet will be expanded based on Rails.env and label name. If there is no match, a blank string is returned.

<!-- Google Tag Manager -->
<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
})(window,document,'script','dataLayer','GTM-YourGtmId1');</script>
<!-- End Google Tag Manager -->

Second, following method immediately after the opening <body> tag on every page of your website.

<%= google_tag_manager_noscript_tag(:foo) %>

Google Tag Manager container snippet will be expanded based on Rails.env and label name. If there is no match, a blank string is returned.

<!-- Google Tag Manager (noscript) -->
<noscript><iframe src="https://www.googletagmanager.com/ns.html?id=GTM-YourGtmId1"
height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
<!-- End Google Tag Manager (noscript) -->

For more detailed GTM please click here to read more.

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

License

gtm_rails is released under the MIT License.

Pinned Loading

  1. BIDS BIDS Public

    BV2BIDS is a command line tool that creates the EEG-BIDS folder hierarchy from BVCD files.

    Python

  2. clientefv clientefv Public

    ModuleScript loader with reusable and easy unified server-client modules for faster game development on Roblox

    Swift

  3. lovebanane lovebanane Public

    Special profile readme repository lovebanane/lovebanane is a ✨special ✨ repository

    Ruby

  4. nubuilt nubuilt Public

    Free landing page template built using nuxt and tailwindcss

    JavaScript