Skip to content
This repository has been archived by the owner on Dec 20, 2022. It is now read-only.

Commit

Permalink
merging 3.2.0 to master
Browse files Browse the repository at this point in the history
  • Loading branch information
wylkon committed Aug 20, 2014
2 parents ecf4f08 + 285bac1 commit a7e50b9
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 3 deletions.
7 changes: 5 additions & 2 deletions source/assets/javascripts/locastyle/_track-events.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ locastyle.trackEvents = (function() {
var links = $("a");
$(links).each(function (index, item) {
var options = {};
options.category = $(item).data("ls-te-category") ? $(item).data("ls-te-category") : null;
options.action = $(item).data("ls-te-action") ? $(item).data("ls-te-action") : 'open_link_#' + $(item).attr("href");
options.label = $(item).data("ls-te-label") ? $(item).data("ls-te-label") : $(item).text();
if($(item).attr("href")) {
Expand Down Expand Up @@ -65,6 +66,7 @@ locastyle.trackEvents = (function() {
var buttons = $("button");
$(buttons).each(function (index, item) {
var options = {};
options.category = $(item).data("ls-te-category") ? $(item).data("ls-te-category") : null;
options.action = $(item).data("ls-te-action") ? $(item).data("ls-te-action") : 'on_page_button_#';
options.label = $(item).data("ls-te-label") ? $(item).data("ls-te-label") : $(item).text();
var modal;
Expand Down Expand Up @@ -98,6 +100,7 @@ locastyle.trackEvents = (function() {
var selects = $("select");
$(selects).each(function (index, item) {
var options = {};
options.category = $(item).data("ls-te-category") ? $(item).data("ls-te-category") : null;
options.action = "select_change_#" + ($(item).attr("id") || $(item).attr("name"));
options.label = "option";
bindSelects(item, options);
Expand All @@ -117,7 +120,7 @@ locastyle.trackEvents = (function() {
options.label = "Open collapse";
}
}
ga('send', 'event', locastyle.trackEvents.eventCategory, options.action, options.label);
ga('send', 'event', options.category || locastyle.trackEvents.eventCategory, options.action, options.label);
});
}

Expand All @@ -133,7 +136,7 @@ locastyle.trackEvents = (function() {
$(element).off("change.ls");
$(element).on("change.ls", function () {
options.label = $(this).val();
ga('send', 'event', locastyle.trackEvents.eventCategory, options.action, options.label);
ga('send', 'event', options.category || locastyle.trackEvents.eventCategory, options.action, options.label);
});
}

Expand Down
2 changes: 1 addition & 1 deletion source/documentacao/funcoes-js/rastreando-eventos.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ type: component
<tbody>
<tr>
<td>data-ls-te-category</td>
<td>Atributo referente a categoria do evento, deve ir na tag <code>body</code>.</td>
<td>Atributo referente a categoria do evento, pode ir na tag <code>body</code> para ficar genérico da página ou em cada elemento para ficar específico. Caso tenha nos dois, o do elemento terá prioridade.</td>
</tr>
<tr>
<td>data-ls-te-action</td>
Expand Down
12 changes: 12 additions & 0 deletions spec/javascripts/fixtures/track-events_fixture.html
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,18 @@ <h3 class="ls-collapse-title">
</div>
</div>

<div id="testing_category_option">
<a id="link_with_category_option" data-ls-te-category="my_custom_category" data-ls-te-action="my_custom_action" data-ls-te-label="my_custom_label" href="/not-this">Open link with options sample</a>

<select name="sample" id="select_sample_with_category_option" data-ls-te-category="my_custom_category">
<option value="today" selected="">Dia atual</option>
<option value="the_value_with_category">Última semana</option>
<option value="last_6_months">Últimos 6 meses</option>
<option value="last_12_months">Últimos 12 meses</option>
</select>
</div>


<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
Expand Down
31 changes: 31 additions & 0 deletions spec/javascripts/track-events_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,21 @@ describe("Track Events: ", function() {
});
});

describe('With data-ls-te-category on trigger: When click on #link_with_category_option', function () {
it('should call ga with expected options as arguments', function () {
$("body").removeAttr("data-ls-te-category");
locastyle.trackEvents.init();
var expectedOptions = {
category: "my_custom_category",
action: "my_custom_action",
label: "my_custom_label"
};
spyOn(window, "ga");
$("#testing_category_option #link_with_category_option").trigger("click.lsTrackEvent");
expect(window.ga).toHaveBeenCalledWith('send', 'event', expectedOptions.category, expectedOptions.action, expectedOptions.label);
});
});

describe("On page links", function () {
describe("When click on #on_page_link_to_nowhere which has the # as href attribute", function () {
it("should call ga with expected iptions as arguments", function () {
Expand Down Expand Up @@ -191,6 +206,22 @@ describe("Track Events: ", function() {
expect(window.ga.calls.count()).toEqual(1);
});
});

describe("When change teh select #select_sample_with_category_option", function () {
it("should call ga with expected options as arguments", function () {
$("body").removeAttr("data-ls-te-category");
var expectedOptions = {
category: "my_custom_category",
action: "select_change_#select_sample_with_category_option",
label: "the_value_with_category"
};
spyOn(window, "ga");
$("#select_sample_with_category_option").val("the_value_with_category");
$("#select_sample_with_category_option").trigger("change");
expect(window.ga).toHaveBeenCalledWith('send', 'event', expectedOptions.category, expectedOptions.action, expectedOptions.label);
});
});

});

describe("Tabs", function () {
Expand Down

0 comments on commit a7e50b9

Please sign in to comment.