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

Adnan/update klaviyo api #3

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions app/jobs/solidus_klaviyo/update_job.rb
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ def perform(list_id, email, properties = {})
SolidusKlaviyo.update_now(list_id, email, properties)
rescue SolidusKlaviyo::RateLimitedError => e
self.class.set(wait: e.retry_after).perform_later(list_id, email, properties)
rescue ActiveJob::DeserializationError => e
self.destroy!
end
end
end
19 changes: 11 additions & 8 deletions lib/solidus_klaviyo/tracker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,22 @@ def from_config
end

def track(event)
klaviyo.track(
event.name,
email: event.email,
customer_properties: event.customer_properties,
properties: event.properties,
time: event.time,
)
klaviyo::Events.create_event(data: {
type: "event",
attributes: {
profile: event.customer_properties,
metric: {
name: event.name
},
properties: event.properties
}
})
end

private

def klaviyo
@klaviyo ||= Klaviyo::Client.new(options.fetch(:api_key))
@klaviyo ||= KlaviyoAPI
end
end
end
2 changes: 1 addition & 1 deletion solidus_klaviyo.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Gem::Specification.new do |spec|
spec.add_dependency 'solidus_support', '~> 0.8'

spec.add_dependency 'httparty', '~> 0.18'
spec.add_dependency 'klaviyo', '~> 1.0'
spec.add_dependency 'klaviyo-api-sdk', '~> 3.0'
spec.add_dependency 'solidus_tracking'

spec.add_development_dependency 'solidus_dev_support'
Expand Down