<commit_before># Gaq

Ever wanted to push a track event from a controller? Set a custom variable from model data? Now you can.

## Installation

Add this line to your application's Gemfile:

    gem 'gaq'

And then execute:

    $ bundle

Or install it yourself as:

    $ gem install gaq

## Setup

1. Require `gaq` from your `application.rb` and configure your web_property_id like this:

    ```ruby
    class MyApplication < Rails::Application
      config.gaq.web_property_id = 'UA-XXYOURID-1'
    end
```

2. Put this in your application layout:

    ```ruby
    <%= render_gaq %>
    ```

    This inserts javascript code for initializing _gaq, your tracking events and the ga.js snippet.
    The ga.js snippet will only be rendered in the production environment, so no real tracking happens
    during development.

3. DONE!

4. If you want to use custom variables, configure them like this:

    ```ruby
    class MyApplication < Rails::Application
      config.gaq.declare_variable :user_gender, scope: :session, slot: 1
    end
    ```

## Usage in the controller

For inserting a track event to be rendered on the current request, do

```ruby
gaq.track_event 'category', 'action', 'label'
```

If you have configured a custom variable like above, do this to set it:

```ruby
gaq.user_gender = 'female'
```

If you need to do any of these before a redirect, use these methods on `gaq.next_request`
instead of `gaq`:

```ruby
gaq.next_request.track_event 'category', 'action', 'label'
```

This feature uses the flash for storing _gaq items between requests.

## 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

### Testing

Test dependencies are declared in the Gemfile. There is a dummy rails application
in `spec-dummy` for integration tests (which we need because gaq keeps state in
the session). Integration specs live inside the dummy app!
All specs are run from guard.<commit_msg>mention test environments and spec tagging in README<commit_after># Gaq

Ever wanted to push a track event from a controller? Set a custom variable from model data? Now you can.

## Installation

Add this line to your application's Gemfile:

    gem 'gaq'

And then execute:

    $ bundle

Or install it yourself as:

    $ gem install gaq

## Setup

1. Require `gaq` from your `application.rb` and configure your web_property_id like this:

    ```ruby
    class MyApplication < Rails::Application
      config.gaq.web_property_id = 'UA-XXYOURID-1'
    end
```

2. Put this in your application layout:

    ```ruby
    <%= render_gaq %>
    ```

    This inserts javascript code for initializing _gaq, your tracking events and the ga.js snippet.
    The ga.js snippet will only be rendered in the production environment, so no real tracking happens
    during development.

3. DONE!

4. If you want to use custom variables, configure them like this:

    ```ruby
    class MyApplication < Rails::Application
      config.gaq.declare_variable :user_gender, scope: :session, slot: 1
    end
    ```

## Usage in the controller

For inserting a track event to be rendered on the current request, do

```ruby
gaq.track_event 'category', 'action', 'label'
```

If you have configured a custom variable like above, do this to set it:

```ruby
gaq.user_gender = 'female'
```

If you need to do any of these before a redirect, use these methods on `gaq.next_request`
instead of `gaq`:

```ruby
gaq.next_request.track_event 'category', 'action', 'label'
```

This feature uses the flash for storing _gaq items between requests.

## 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

### Testing

Test dependencies are declared in the Gemfile.
All specs are run from guard.

#### Dummy app

There is a dummy rails application
in `spec-dummy` for integration tests, which we need because gaq keeps state in
the session. The integration specs are located inside of it.

It has two test environments, `test_static` and `test_dynamic`. Specs tagged with
`:static` will not be run under `test_dynamic` and vice versa.
{'fraction_non_alphanumeric': 0.08394327538883806, 'fraction_numerical': 0.005032021957913998, 'mean_word_length': 3.7275675675675677, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '31659', 'n_tokens_mistral': 1336, 'n_tokens_neox': 1232, 'n_words': 596}