workarea-facebook_conversion_tracking 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +22 -0
- data/Gemfile +9 -0
- data/LICENSE +7 -0
- data/README.md +63 -0
- data/app/assets/javascripts/workarea/storefront/facebook_conversion_tracking/modules/adapter.js +116 -0
- data/app/controllers/workarea/storefront/facebook_conversion_tracking_controller.rb +11 -0
- data/app/helpers/workarea/facebook_conversion_tracking/analytics/helper.rb +21 -0
- data/app/views/workarea/storefront/facebook/_pixel.html.haml +12 -0
- data/bin/rails +20 -0
- data/config/initializers/appends.rb +11 -0
- data/config/initializers/fields.rb +23 -0
- data/config/routes.rb +4 -0
- data/lib/workarea/facebook_conversion_tracking.rb +37 -0
- data/lib/workarea/facebook_conversion_tracking/engine.rb +13 -0
- data/lib/workarea/facebook_conversion_tracking/gateway.rb +68 -0
- data/lib/workarea/facebook_conversion_tracking/models/events/add_to_cart.rb +26 -0
- data/lib/workarea/facebook_conversion_tracking/models/events/base.rb +37 -0
- data/lib/workarea/facebook_conversion_tracking/models/events/purchase.rb +34 -0
- data/lib/workarea/facebook_conversion_tracking/version.rb +5 -0
- data/workarea-facebook_conversion_tracking.gemspec +20 -0
- metadata +78 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 0054cb6c3c1ca17de81bfe377b7b6708e9d42144
|
4
|
+
data.tar.gz: 92ebfb7e98c90b857425c61657b4f822e7db9084
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 8e7e4156378a3f19c4d2ddd47b834fb397721458331a5d64f7c2e090bf9042582b1395934b25114740ea3ab8e9b282609be69b2a4e48b19876c0fdc4c179f180
|
7
|
+
data.tar.gz: f1beaff66340367f4495566b26bca5b1c1a5d5c8fc656b1d71032bdf2a385e1b17e2d8f5e325f4ea47f22baf4d183da441ce9201d9d5e50b4898aa016fa32941
|
data/.gitignore
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
.bundle/
|
2
|
+
log/*.log
|
3
|
+
pkg/
|
4
|
+
test/dummy/db/*.sqlite3
|
5
|
+
test/dummy/db/*.sqlite3-journal
|
6
|
+
test/dummy/log/*.log
|
7
|
+
test/dummy/tmp/
|
8
|
+
.DS_Store
|
9
|
+
.byebug_history
|
10
|
+
.bundle/
|
11
|
+
.sass-cache/
|
12
|
+
Gemfile.lock
|
13
|
+
pkg/
|
14
|
+
test/dummy/tmp/
|
15
|
+
test/dummy/public/
|
16
|
+
log/*.log
|
17
|
+
test/dummy/log/*.log
|
18
|
+
test/dummy/db/*.sqlite3
|
19
|
+
test/dummy/db/*.sqlite3-journal
|
20
|
+
node_modules
|
21
|
+
test/reports
|
22
|
+
.rubocop-http*
|
data/Gemfile
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
git_source(:github) { |repo| "git@github.com:#{repo}.git" }
|
3
|
+
|
4
|
+
gemspec
|
5
|
+
|
6
|
+
# To use a debugger
|
7
|
+
# gem 'byebug', group: [:development, :test]
|
8
|
+
|
9
|
+
gem 'workarea', git: 'https://github.com/workarea-commerce/workarea.git', branch: 'v3.5-stable'
|
data/LICENSE
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
Copyright 2020
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
4
|
+
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
6
|
+
|
7
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
Workarea Facebook Conversion Tracking
|
2
|
+
================================================================================
|
3
|
+
|
4
|
+
A Facebook conversion tracking plugin for the Workarea Commerce platform. This integration sends events via browser and server
|
5
|
+
to Facebook Business Manager.
|
6
|
+
|
7
|
+
Getting Started
|
8
|
+
--------------------------------------------------------------------------------
|
9
|
+
|
10
|
+
This gem contains a Rails engine that must be mounted onto a host Rails application.
|
11
|
+
|
12
|
+
Then add the gem to your application's Gemfile specifying the source:
|
13
|
+
|
14
|
+
# ...
|
15
|
+
gem 'workarea-facebook_conversion_tracking'
|
16
|
+
# ...
|
17
|
+
|
18
|
+
Update your application's bundle.
|
19
|
+
|
20
|
+
cd path/to/application
|
21
|
+
bundle
|
22
|
+
|
23
|
+
Features
|
24
|
+
--------------------------------------------------------------------------------
|
25
|
+
|
26
|
+
This integration supports the following features:
|
27
|
+
* Adding the Facebook pixel
|
28
|
+
* Support the following facebook standard events out of the box:
|
29
|
+
* AddtoCart
|
30
|
+
* Purchase
|
31
|
+
|
32
|
+
* Each event will require adjusting custom data on a per project need
|
33
|
+
|
34
|
+
Configuration
|
35
|
+
--------------------------------------------------------------------------------
|
36
|
+
|
37
|
+
**For Workarea v3.5 and Greater**
|
38
|
+
Facebook Conversion Tracking can be configured via the settings section in the Workarea admin console.
|
39
|
+
Available settings are:
|
40
|
+
* pixel id
|
41
|
+
* access token
|
42
|
+
* test code
|
43
|
+
|
44
|
+
|
45
|
+
**For Workarea v3.0 to V3.4**
|
46
|
+
Add the following to your secrets:
|
47
|
+
|
48
|
+
facebook_conversion_tracking:
|
49
|
+
pixel_id: YOUR-PIXEL-ID
|
50
|
+
access_token: YOUR-ACCESS-TOKEN
|
51
|
+
test_code: YOUR-TEST-CODE
|
52
|
+
|
53
|
+
Documentation
|
54
|
+
--------------------------------------------------------------------------------
|
55
|
+
See [https://developers.facebook.com/docs/facebook-pixel/implementation/conversion-tracking](https://developers.facebook.com/docs/facebook-pixel/implementation/conversion-tracking) for Conversion Tracking Documentation.
|
56
|
+
|
57
|
+
See [https://developer.workarea.com](https://developer.workarea.com) for Workarea platform documentation.
|
58
|
+
|
59
|
+
License
|
60
|
+
--------------------------------------------------------------------------------
|
61
|
+
|
62
|
+
Workarea Sezzle is released under the MIT open source agreement.
|
63
|
+
|
data/app/assets/javascripts/workarea/storefront/facebook_conversion_tracking/modules/adapter.js
ADDED
@@ -0,0 +1,116 @@
|
|
1
|
+
WORKAREA.analytics.registerAdapter('facebookConversionTracking', function () {
|
2
|
+
'use strict';
|
3
|
+
|
4
|
+
return {
|
5
|
+
addToCart: function (payload) {
|
6
|
+
var eventName = 'AddToCart',
|
7
|
+
contentType = 'product_group',
|
8
|
+
eventId = payload.event_id,
|
9
|
+
products = [
|
10
|
+
{
|
11
|
+
id: payload.id,
|
12
|
+
name: payload.name,
|
13
|
+
sku: payload.sku,
|
14
|
+
sale: payload.sale,
|
15
|
+
price: payload.price,
|
16
|
+
category: payload.category
|
17
|
+
}
|
18
|
+
],
|
19
|
+
serverPayload = {
|
20
|
+
event: eventName,
|
21
|
+
event_id: eventId,
|
22
|
+
event_source_url: window.location.href,
|
23
|
+
content_type: contentType,
|
24
|
+
products: products
|
25
|
+
},
|
26
|
+
browserPayload = {
|
27
|
+
name: [payload.name],
|
28
|
+
sku: [payload.sku],
|
29
|
+
sale: [payload.sale],
|
30
|
+
price: [payload.price],
|
31
|
+
category: [payload.category],
|
32
|
+
content_type: contentType,
|
33
|
+
content_ids: [payload.sku]
|
34
|
+
};
|
35
|
+
|
36
|
+
$.ajax({
|
37
|
+
type: 'POST',
|
38
|
+
url: WORKAREA.routes.storefront.facebookConversionTrackingAddToCartPath(),
|
39
|
+
data: serverPayload
|
40
|
+
});
|
41
|
+
|
42
|
+
if (_.isUndefined(window.fbq)) {
|
43
|
+
setTimeout(function() {
|
44
|
+
fbq('track', eventName, browserPayload, { eventID: eventId });
|
45
|
+
}, 3000);
|
46
|
+
} else {
|
47
|
+
fbq('track', eventName, browserPayload, { eventID: eventId });
|
48
|
+
};
|
49
|
+
},
|
50
|
+
|
51
|
+
checkoutOrderPlaced: function (payload) {
|
52
|
+
var eventName = 'Purchase',
|
53
|
+
contentType = 'product_group',
|
54
|
+
eventId = payload.event_id,
|
55
|
+
products = [];
|
56
|
+
|
57
|
+
_.each(payload.items, function (impression) {
|
58
|
+
products.push({
|
59
|
+
id: impression.product_id,
|
60
|
+
name: impression.product_name,
|
61
|
+
sku: impression.sku,
|
62
|
+
price: impression.price,
|
63
|
+
quantity: impression.quantity,
|
64
|
+
category: impression.category
|
65
|
+
});
|
66
|
+
});
|
67
|
+
|
68
|
+
var serverPayload = {
|
69
|
+
event: eventName,
|
70
|
+
event_id: eventId,
|
71
|
+
event_source_url: window.location.href,
|
72
|
+
id: payload.id,
|
73
|
+
promo_codes: payload.promo_codes,
|
74
|
+
shipping_service: payload.shipping_service,
|
75
|
+
shipping_total: payload.shipping_total,
|
76
|
+
tax_total: payload.tax_total,
|
77
|
+
tenders: payload.tenders,
|
78
|
+
value: payload.total_price,
|
79
|
+
currency: payload.currency,
|
80
|
+
content_type: contentType,
|
81
|
+
products: products
|
82
|
+
},
|
83
|
+
browserPayload = {
|
84
|
+
id: payload.id,
|
85
|
+
promo_codes: payload.promo_codes,
|
86
|
+
shipping_service: payload.shipping_service,
|
87
|
+
shipping_total: payload.shipping_total,
|
88
|
+
tax_total: payload.tax_total,
|
89
|
+
tenders: payload.tenders,
|
90
|
+
value: payload.total_price,
|
91
|
+
currency: payload.currency,
|
92
|
+
content_type: contentType,
|
93
|
+
content_ids: _.map(products, 'id'),
|
94
|
+
name: _.map(products, 'name'),
|
95
|
+
sku: _.map(products, 'sku'),
|
96
|
+
price: _.map(products, 'price'),
|
97
|
+
quantity: _.map(products, 'quantity'),
|
98
|
+
category: _.map(products, 'category')
|
99
|
+
};
|
100
|
+
|
101
|
+
$.ajax({
|
102
|
+
type: 'POST',
|
103
|
+
url: WORKAREA.routes.storefront.facebookConversionTrackingPurchasePath(),
|
104
|
+
data: serverPayload
|
105
|
+
});
|
106
|
+
|
107
|
+
if (_.isUndefined(window.fbq)) {
|
108
|
+
setTimeout(function() {
|
109
|
+
fbq('track', eventName, browserPayload, { eventID: eventId });
|
110
|
+
}, 3000);
|
111
|
+
} else {
|
112
|
+
fbq('track', eventName, browserPayload, { eventID: eventId });
|
113
|
+
};
|
114
|
+
},
|
115
|
+
};
|
116
|
+
});
|
@@ -0,0 +1,11 @@
|
|
1
|
+
module Workarea
|
2
|
+
class Storefront::FacebookConversionTrackingController < Storefront::ApplicationController
|
3
|
+
def add_to_cart
|
4
|
+
Workarea::FacebookConversionTracking::Models::Events::AddToCart.new(request, params).perform
|
5
|
+
end
|
6
|
+
|
7
|
+
def purchase
|
8
|
+
Workarea::FacebookConversionTracking::Models::Events::Purchase.new(request, params).perform
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Workarea
|
2
|
+
module FacebookConversionTracking
|
3
|
+
module Analytics
|
4
|
+
module Helper
|
5
|
+
def product_analytics_data(product)
|
6
|
+
super.merge(event_id: event_id)
|
7
|
+
end
|
8
|
+
|
9
|
+
def order_analytics_data(order)
|
10
|
+
super.merge(event_id: event_id, currency: order.model.total_value.currency.iso_code)
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def event_id
|
16
|
+
"#{Time.current.to_i}_#{rand(10000)}"
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
- if Workarea::FacebookConversionTracking.pixel_id.present?
|
2
|
+
%iframe{ src: "https://www.facebook.com/tr?id=#{Workarea::FacebookConversionTracking.pixel_id}&ev=PageView&noscript=1", height: 1, width: 1, style: 'display:none;visibility:hidden;' }
|
3
|
+
:javascript
|
4
|
+
!function(f,b,e,v,n,t,s)
|
5
|
+
{if(f.fbq)return;n=f.fbq=function(){n.callMethod?
|
6
|
+
n.callMethod.apply(n,arguments):n.queue.push(arguments)};
|
7
|
+
if(!f._fbq)f._fbq=n;n.push=n;n.loaded=!0;n.version='2.0';
|
8
|
+
n.queue=[];t=b.createElement(e);t.async=!0;
|
9
|
+
t.src=v;s=b.getElementsByTagName(e)[0];
|
10
|
+
s.parentNode.insertBefore(t,s)}(window, document,'script',
|
11
|
+
'https://connect.facebook.net/en_US/fbevents.js');
|
12
|
+
fbq('init', "#{Workarea::FacebookConversionTracking.pixel_id}");
|
data/bin/rails
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# This command will automatically be run when you run "rails" with Rails gems
|
3
|
+
# installed from the root of your application.
|
4
|
+
|
5
|
+
ENGINE_ROOT = File.expand_path('../..', __FILE__)
|
6
|
+
ENGINE_PATH = File.expand_path('../../lib/workarea/facebook_conversion_tracking/engine', __FILE__)
|
7
|
+
APP_PATH = File.expand_path('../../test/dummy/config/application', __FILE__)
|
8
|
+
|
9
|
+
# Set up gems listed in the Gemfile.
|
10
|
+
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
|
11
|
+
require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])
|
12
|
+
|
13
|
+
require 'action_controller/railtie'
|
14
|
+
require 'action_view/railtie'
|
15
|
+
require 'action_mailer/railtie'
|
16
|
+
require 'rails/test_unit/railtie'
|
17
|
+
require 'sprockets/railtie'
|
18
|
+
require 'teaspoon-mocha'
|
19
|
+
|
20
|
+
require 'rails/engine/commands'
|
@@ -0,0 +1,23 @@
|
|
1
|
+
if Workarea::Configuration.respond_to?(:define_fields)
|
2
|
+
Workarea::Configuration.define_fields do
|
3
|
+
fieldset 'Facebook Conversion Tracking' do
|
4
|
+
field 'Pixel Id',
|
5
|
+
type: :string,
|
6
|
+
description: 'Facebook Pixel Id',
|
7
|
+
allow_blank: false,
|
8
|
+
encrypted: false
|
9
|
+
|
10
|
+
field 'Access Token',
|
11
|
+
type: :string,
|
12
|
+
description: 'Business Manager Access Token',
|
13
|
+
allow_blank: false,
|
14
|
+
encrypted: true
|
15
|
+
|
16
|
+
field 'Test Code',
|
17
|
+
type: :string,
|
18
|
+
description: 'Business Manager Test Code',
|
19
|
+
allow_blank: true,
|
20
|
+
encrypted: false
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/config/routes.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'workarea'
|
2
|
+
require 'workarea/storefront'
|
3
|
+
require 'workarea/admin'
|
4
|
+
|
5
|
+
require 'workarea/facebook_conversion_tracking/engine'
|
6
|
+
require 'workarea/facebook_conversion_tracking/version'
|
7
|
+
|
8
|
+
require 'workarea/facebook_conversion_tracking/models/events/base'
|
9
|
+
require 'workarea/facebook_conversion_tracking/models/events/add_to_cart'
|
10
|
+
require 'workarea/facebook_conversion_tracking/models/events/purchase'
|
11
|
+
require 'workarea/facebook_conversion_tracking/gateway'
|
12
|
+
|
13
|
+
module Workarea
|
14
|
+
module FacebookConversionTracking
|
15
|
+
# used for <= 3.5, these creds come from secrets isntead of encrypted in the
|
16
|
+
# 3.5 configurations system.
|
17
|
+
def self.credentials
|
18
|
+
(Rails.application.secrets.facebook_conversion_tracking || {}).deep_symbolize_keys
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.pixel_id
|
22
|
+
Workarea.config.facebook_conversion_tracking_pixel_id || credentials[:pixel_id]
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.access_token
|
26
|
+
Workarea.config.facebook_conversion_tracking_access_token || credentials[:access_token]
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.test_code
|
30
|
+
Workarea.config.facebook_conversion_tracking_test_code || credentials[:test_code]
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.configured?
|
34
|
+
pixel_id.present? && access_token.present?
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module Workarea
|
2
|
+
module FacebookConversionTracking
|
3
|
+
class Engine < ::Rails::Engine
|
4
|
+
include Workarea::Plugin
|
5
|
+
isolate_namespace Workarea::FacebookConversionTracking
|
6
|
+
|
7
|
+
config.to_prepare do
|
8
|
+
Workarea::ApplicationController.helper(Workarea::FacebookConversionTracking::Analytics::Helper)
|
9
|
+
Workarea::Storefront::ApplicationController.helper(Workarea::FacebookConversionTracking::Analytics::Helper)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
require 'uri'
|
3
|
+
require 'json'
|
4
|
+
|
5
|
+
module Workarea
|
6
|
+
class FacebookConversionTrackingGateway
|
7
|
+
def initialize(payload)
|
8
|
+
@payload = payload
|
9
|
+
end
|
10
|
+
|
11
|
+
def send
|
12
|
+
begin
|
13
|
+
response = conn.post do |req|
|
14
|
+
req.params['data'] = @payload.to_json
|
15
|
+
end
|
16
|
+
|
17
|
+
handle_response(response)
|
18
|
+
rescue => e
|
19
|
+
Raven.capture_message("Facebook Conversion Tracking POST Error: #{e}", level: 'error')
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def handle_response(response)
|
26
|
+
parsed_resp = JSON.parse(response.body)
|
27
|
+
|
28
|
+
if response.status != 200
|
29
|
+
Raven.capture_message("Facebook Conversion Tracking Error: #{parsed_resp}", level: 'error')
|
30
|
+
else
|
31
|
+
parsed_resp
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def conn
|
36
|
+
@conn ||=
|
37
|
+
Faraday.new(
|
38
|
+
url: URI.parse(url),
|
39
|
+
params: conn_params,
|
40
|
+
headers: { 'Content-Type' => 'application/json' }
|
41
|
+
)
|
42
|
+
end
|
43
|
+
|
44
|
+
# We only want to use the test code when testing on dev.
|
45
|
+
def conn_params
|
46
|
+
return unless Workarea::FacebookConversionTracking.configured?
|
47
|
+
|
48
|
+
test_code = Rails.env.development? ? { test_event_code: test_code } : {}
|
49
|
+
{ access_token: access_token }.merge(test_code)
|
50
|
+
end
|
51
|
+
|
52
|
+
def url
|
53
|
+
"https://graph.facebook.com/v10.0/#{pixel_id}/events"
|
54
|
+
end
|
55
|
+
|
56
|
+
def pixel_id
|
57
|
+
Workarea::FacebookConversionTracking.pixel_id
|
58
|
+
end
|
59
|
+
|
60
|
+
def access_token
|
61
|
+
Workarea::FacebookConversionTracking.access_token
|
62
|
+
end
|
63
|
+
|
64
|
+
def test_code
|
65
|
+
Workarea::FacebookConversionTracking.test_code
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module Workarea
|
2
|
+
module FacebookConversionTracking
|
3
|
+
module Models
|
4
|
+
module Events
|
5
|
+
class AddToCart < Base
|
6
|
+
def perform
|
7
|
+
event = build_event
|
8
|
+
|
9
|
+
custom_data = {
|
10
|
+
content_type: @params[:content_type],
|
11
|
+
content_ids: products.pluck(:id),
|
12
|
+
name: products.pluck(:name),
|
13
|
+
sku: products.pluck(:sku),
|
14
|
+
sale: products.pluck(:sale),
|
15
|
+
price: products.pluck(:price)
|
16
|
+
}
|
17
|
+
|
18
|
+
event[:custom_data] = custom_data
|
19
|
+
|
20
|
+
send([event])
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module Workarea
|
2
|
+
module FacebookConversionTracking
|
3
|
+
module Models
|
4
|
+
module Events
|
5
|
+
class Base
|
6
|
+
def initialize(request, params)
|
7
|
+
@request = request
|
8
|
+
@params = params
|
9
|
+
end
|
10
|
+
|
11
|
+
def products
|
12
|
+
@params[:products].values
|
13
|
+
end
|
14
|
+
|
15
|
+
def build_event
|
16
|
+
{
|
17
|
+
event_name: @params[:event],
|
18
|
+
event_id: @params[:event_id],
|
19
|
+
event_time: Time.current.to_i,
|
20
|
+
event_source_url: @params[:event_source_url],
|
21
|
+
action_source: 'website',
|
22
|
+
user_data: {
|
23
|
+
client_ip_address: @request.remote_ip,
|
24
|
+
client_user_agent: @request.user_agent
|
25
|
+
},
|
26
|
+
custom_data: {}
|
27
|
+
}
|
28
|
+
end
|
29
|
+
|
30
|
+
def send(event)
|
31
|
+
Workarea::FacebookConversionTrackingGateway.new(event).send
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module Workarea
|
2
|
+
module FacebookConversionTracking
|
3
|
+
module Models
|
4
|
+
module Events
|
5
|
+
class Purchase < Base
|
6
|
+
def perform
|
7
|
+
event = build_event
|
8
|
+
|
9
|
+
custom_data = {
|
10
|
+
id: @params[:id],
|
11
|
+
promo_codes: @params[:promo_codes],
|
12
|
+
shipping_service: @params[:shipping_service],
|
13
|
+
shipping_total: @params[:shipping_total],
|
14
|
+
tax_total: @params[:tax_total],
|
15
|
+
tenders: @params[:tenders],
|
16
|
+
value: @params[:value], #required
|
17
|
+
currency: @params[:currency], #required
|
18
|
+
content_type: @params[:content_type], #required for Dynamic Ads
|
19
|
+
content_ids: products.pluck(:id), #required for Dynamic Ads
|
20
|
+
name: products.pluck(:name),
|
21
|
+
sku: products.pluck(:sku),
|
22
|
+
price: products.pluck(:price),
|
23
|
+
quantity: products.pluck(:quantity),
|
24
|
+
category: products.pluck(:category)
|
25
|
+
}
|
26
|
+
event[:custom_data] = custom_data
|
27
|
+
|
28
|
+
send([event])
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
$LOAD_PATH.push File.expand_path('../lib', __FILE__)
|
2
|
+
|
3
|
+
# Maintain your gem's version:
|
4
|
+
require 'workarea/facebook_conversion_tracking/version'
|
5
|
+
|
6
|
+
# Describe your gem and declare its dependencies:
|
7
|
+
Gem::Specification.new do |spec|
|
8
|
+
spec.name = 'workarea-facebook_conversion_tracking'
|
9
|
+
spec.version = Workarea::FacebookConversionTracking::VERSION
|
10
|
+
spec.authors = ['Jurgen Hahn']
|
11
|
+
spec.email = ['jurgen@syatt.io']
|
12
|
+
spec.homepage = 'https://github.com/syatt-io/workarea-facebook-conversion-tracking'
|
13
|
+
spec.summary = 'Workarea Commerce plugin for facebook conversion tracking'
|
14
|
+
spec.description = 'A facebook conversion tracking plugin into the Workarea Commerce system.'
|
15
|
+
spec.license = 'Nonstandard'
|
16
|
+
|
17
|
+
spec.files = `git ls-files`.split("\n")
|
18
|
+
|
19
|
+
spec.add_dependency 'workarea', '~> 3.x'
|
20
|
+
end
|
metadata
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: workarea-facebook_conversion_tracking
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jurgen Hahn
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2021-04-29 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: workarea
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 3.x
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 3.x
|
27
|
+
description: A facebook conversion tracking plugin into the Workarea Commerce system.
|
28
|
+
email:
|
29
|
+
- jurgen@syatt.io
|
30
|
+
executables: []
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- ".gitignore"
|
35
|
+
- Gemfile
|
36
|
+
- LICENSE
|
37
|
+
- README.md
|
38
|
+
- app/assets/javascripts/workarea/storefront/facebook_conversion_tracking/modules/adapter.js
|
39
|
+
- app/controllers/workarea/storefront/facebook_conversion_tracking_controller.rb
|
40
|
+
- app/helpers/workarea/facebook_conversion_tracking/analytics/helper.rb
|
41
|
+
- app/views/workarea/storefront/facebook/_pixel.html.haml
|
42
|
+
- bin/rails
|
43
|
+
- config/initializers/appends.rb
|
44
|
+
- config/initializers/fields.rb
|
45
|
+
- config/routes.rb
|
46
|
+
- lib/workarea/facebook_conversion_tracking.rb
|
47
|
+
- lib/workarea/facebook_conversion_tracking/engine.rb
|
48
|
+
- lib/workarea/facebook_conversion_tracking/gateway.rb
|
49
|
+
- lib/workarea/facebook_conversion_tracking/models/events/add_to_cart.rb
|
50
|
+
- lib/workarea/facebook_conversion_tracking/models/events/base.rb
|
51
|
+
- lib/workarea/facebook_conversion_tracking/models/events/purchase.rb
|
52
|
+
- lib/workarea/facebook_conversion_tracking/version.rb
|
53
|
+
- workarea-facebook_conversion_tracking.gemspec
|
54
|
+
homepage: https://github.com/syatt-io/workarea-facebook-conversion-tracking
|
55
|
+
licenses:
|
56
|
+
- Nonstandard
|
57
|
+
metadata: {}
|
58
|
+
post_install_message:
|
59
|
+
rdoc_options: []
|
60
|
+
require_paths:
|
61
|
+
- lib
|
62
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
63
|
+
requirements:
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '0'
|
67
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
68
|
+
requirements:
|
69
|
+
- - ">="
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: '0'
|
72
|
+
requirements: []
|
73
|
+
rubyforge_project:
|
74
|
+
rubygems_version: 2.6.14.1
|
75
|
+
signing_key:
|
76
|
+
specification_version: 4
|
77
|
+
summary: Workarea Commerce plugin for facebook conversion tracking
|
78
|
+
test_files: []
|