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

Allow for dynamic Facebook Pixel options #101

Merged
merged 5 commits into from
Jan 24, 2018
Merged

Allow for dynamic Facebook Pixel options #101

merged 5 commits into from
Jan 24, 2018

Conversation

smadeja
Copy link
Contributor

@smadeja smadeja commented Jan 17, 2018

This allows the Facebook Pixel id (as well as other tracker options) to be dynamic, and change on a per-request basis. It's based on some other trackers that offer this functionality (:user_id on the Google Analytics one, for example).

end
end
end
end
Copy link
Contributor

@bumi bumi Jan 17, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a similar method is in https://github.com/railslove/rack-tracker/pull/97/files#diff-8c96bad81146eddcac1965e5645e68f3R11 #97

I think it would be awesome to move it to the Rack::Tracker::Handler class that all the trackers can access it.
What do you think? could you do that?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I'll give it a shot!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yay, that would be a great addition.

* Require `ALLOWED_TRACKER_OPTIONS` to be defined on all classes
  that use it

* Extract key, and value transformations into separate methods
  that can be overriden in descendants
# Transformations to be applied to tracker option values.
# Override in descendants, if necessary.
def tracker_option_value(value)
value.to_s
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we need the to_s?
If we use it in the template the <%= %> does a to_s anyway, isn't it?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's what the Google Analytics tracker is currently doing. It can potentially make a difference in that case, because the values aren't outputted directly using the <%= %> there, but rather the entire hash is converted to JSON, so it's a difference between "{\"one\":1}" and "{\"one\":\"1\"}". That said, it probably shouldn't be the default behaviour, I can move it to the GA tracker.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok, I see. good point.
I guess the convention could be that call should return a string. but I am fine either way.
If that's the case right now in the analytics tracker then let's do it like that.

end
end
end
end
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good!! should also add some specs for that on the handler level.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, I'll try to come up with some tests for this. Thanks for the feedback!

Put it in the Google Analytics tracker.
Base them off of the Google Analytics specs.
@smadeja
Copy link
Contributor Author

smadeja commented Jan 22, 2018

@bumi Would you like me to make some more changes?

@DonSchado
Copy link
Collaborator

I personally don't like the use of a constant in the facebook handler. Since constants are hard to mock etc... I would prefer something like a hook method on the top handler class.
If we do it on the class level it would also become more macro/dsl like.

But maybe this is something we can refactor later... and go with this solution for now...

@bumi
Copy link
Contributor

bumi commented Jan 22, 2018

nice! looks great! thanks again for the contribution.

@DonSchado I actually agree. also it would then be similar to the self.position= call.
But that's also used in the other PR for the google stuff (https://github.com/railslove/rack-tracker/pull/97/files#diff-8c96bad81146eddcac1965e5645e68f3R2)
@smadeja what do you think?
we could do that the same way as: https://github.com/railslove/rack-tracker/blob/master/lib/rack/tracker/handler.rb#L13-L14

@bumi
Copy link
Contributor

bumi commented Jan 22, 2018

should actually be simple to replace, and I think it is more consistent then.

* Define the :allowed_tracker_options attribute on the Handler class,
  and set it to an empty array by default.

* Use the new class attribute in #tracker_options.

* Remove allowed option stubbing from Google Analytics specs.
  Use a real option instead.

* Redo the #tracker_options specs.
@smadeja
Copy link
Contributor Author

smadeja commented Jan 22, 2018

The constant is dead. ;-)

@bumi
Copy link
Contributor

bumi commented Jan 24, 2018

awesome! let's merge! @DonSchado you're last chance to comment.

@bumi bumi merged commit 7fbe4ca into railslove:master Jan 24, 2018
@DonSchado
Copy link
Collaborator

💚

@smadeja smadeja deleted the dynamic-facebook branch January 29, 2018 09:31
@DonSchado
Copy link
Collaborator

Finally this is included in the last release 1.6.0, sorry that it took so long :/

@smadeja
Copy link
Contributor Author

smadeja commented Mar 27, 2018

Sweet, thanks!

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

Successfully merging this pull request may close these issues.

3 participants