Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement Piwik Ecommerce tags #7

Open
berkes opened this issue Oct 14, 2012 · 5 comments
Open

Implement Piwik Ecommerce tags #7

berkes opened this issue Oct 14, 2012 · 5 comments
Milestone

Comments

@berkes
Copy link
Contributor

berkes commented Oct 14, 2012

Hi there, for a rails/spree ecommerce site, I am implementing piwik e-commerce tags.

They would be optionally: as in: you can toggle them on in your piwik.yml and after enabling, push ecommerce variables into the tags from your controllers. As outlined in the usage chapter in the Readme.

A few questions beforehand:

  • Is this a feature that would be welcomed in this engine? Else I will close this ticket and won't nag you with a pull-request.
  • Any implementation details you want to see in there? Or anything you want different?
@halfdan
Copy link
Owner

halfdan commented Oct 14, 2012

Hi!

This is a very nice idea, but it should be more flexible in terms of configuration. Right now I am working on an extension for the view helper to provide access to the JavaScript Tracking API.

It might look like this:

<%= piwik_tracking_tag do |piwik| %>
  <% piwik.set_custom_variable 1, "Name", "Value", Scope" %>
  <% piwik.track_goal 1 %>
<% end %>

This will output JavaScript for both tracking options (async/sync). If you have any comments on this implementation I'd be happy to hear them. I am not quite sure how to make this accessible via the controller, but I'll figure something out.

To answer your questions:

Yes, this certainly is a feature I'd like to see implemented. I will push my current implementation (as described in the snipped) in a few days. Introducing another view (especially one that is conflicting the use_async: true setting in the config) might not be the best choice.

@berkes
Copy link
Contributor Author

berkes commented Oct 15, 2012

First off: I'll wait untill you have pushed your implementation, so I can make the ecommerce-tags use the same syntax, DSL and templates.

I like the block-approach, but I think for many of the variables, the view is the wrong place to pass them on to the tag, not? Would it not be better to build the tag in the controller at that?

set_piwik_tracking_tag do |piwik|
  piwik.track_goal 1 if @comment.published?
end

This goes for the e-commerce tags for sure: many of the variables are conditionally set, calculated and prepared in one or more of the various controllers. It would become really messy if I had to have code in application.rb like :

<%= piwik_tracking_tag do |piwik| %>
  <% if (cart.not_empty? && cart.has_new_items? && current_page_is_cart?) %>
     <% piwik.ecommerce.update_cart(@cart.total) %>
 <% end %>
<% end %>

It seems cleaner to me, to determine these tags in the controller(s) and push them into the piwik-tag from there. But then again, I am not extremely familiar with the exact boundiies of what belongs in a controller, view or even model :)

edit clarified my "messy" code my expanding it into a more realistic example.

halfdan added a commit that referenced this issue Feb 3, 2013
is somewhat of an issue. Specified the API in a huge data structure for
now.

If you know some better way to do this, let me know.

method_missing is used to check whether a method exists, validate
the arguments and add it to list. The list will be converted to valid
JS calls (based on use_async?) and rendered out for piwik_tracking_tag.

refs #7, #10
@halfdan
Copy link
Owner

halfdan commented Feb 13, 2013

@berkes I'll push the first refined version of the DSL tomorrow. It would be great if you could take a look at it and tell me if that allows you to implement ECommerce Tracking easily. I'm open to suggestions!

@berkes
Copy link
Contributor Author

berkes commented Feb 13, 2013

Thanks for all the work; I am not sure if I can evaluate the code tomorrow, but I will get back ASAP.

@halfdan
Copy link
Owner

halfdan commented Feb 14, 2013

Take your time - I am not very happy with the code anyways (see branch dsl btw.), some parts are still missing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants