Giter Site home page Giter Site logo

jamescotterill / rack_google_tag_manager Goto Github PK

View Code? Open in Web Editor NEW

This project forked from onthebeach/rack_google_tag_manager

0.0 1.0 0.0 10 KB

Rack Middleware to inject Google Tag Manager in you rack based application.

License: MIT License

Ruby 98.02% HTML 1.98%

rack_google_tag_manager's Introduction

Rack Google Tag Manager Build Status

Rack Middleware to inject Google Tag Manager code snippet into all html responses with body tag for rack based applications.

Installation

Add this line to your application's Gemfile:

gem 'rack_google_tag_manager'

And then execute:

$ bundle install

Usage

Rails

Add this line to your application's config/application.rb:

config.middleware.use 'Rack::GoogleTagManager', tracker: 'GTM-XXXXXX'

To pass inforamtion to GTM from your application you can do it with a JavaScript array called dataLayer. There are two ways to use it:

  1. dataLayer = [{ 'data': 'myData' }]
  2. dataLayer.push({ 'data': 'myData' })

The first one will overwrite all existing values that were previously passed to the service, while the second will append the new values to the existing ones.

In order for the push API so be usable, the dataLayer must first be declared as an array, the GTM JavaScript snippet inserted at the top of the body will declare it for you.

If your tags need to fire when pages load, but need information beyond URL and referrer, you may need to define the dataLayer and pushes information to it. Add this code above the container snippet so that the data layer information is available on page load. Note that every page must have the code to create a dataLayer and push information to it; the dataLayer does not persist across pages.

Contributing

  1. Fork it ( http://github.com/onthebeach/rack_google_tag_manager/fork )
  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

rack_google_tag_manager's People

Contributors

ancorcruz avatar cleytonmessias avatar jamescotterill avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.