Third Party Code It has many names
• Re-marketing Tracking Pixels • Widgets (Chat, Reviews, Popups, Payments) • Integrations (Analytics, Tag Containers, A / B Testing) • All want to be the first to load and claim they don’t affect site performance (wink)
Slide 5
index.vue
Third Party Poison Starts To Leak In
Slide 6
index.vue
Then it gets worse..
Slide 7
• Poisons the purpose of your pages and components
• Confusing Object Structure • Error Prone • Not Maintainable at Scale Josh, why is this so bad?
Slide 8
? t i if x e w o d w o H
Slide 9
Plugins
Slide 10
Plugins Are • Injected Javascript functions
• Ran per hit (server) and when app starts (client)
• Exposed to all components, pages and layouts
• Included in the context object
Slide 11
Third Party Javascript in a plugin
Slide 12
Slide 13
This Rocks! Focused One integration per file Natural It’s just Javascript Flexible Easy to extend and optimize
Slide 14
Changing Service Providers Is a Pain Problem 2
Slide 15
Providers Change It’s a matter of when, not if
Chat Live Person -> Drift Payments Stripe -> Bolt Tag Containers GTM -> Segment
Slide 16
Ho wd ow ef ix i t?
Slide 17
Abstractions!
Using plugins..
Slide 18
• You have external integrations that may change • You have a feature that is fulfilled by different providers • You want a clean line of separation between your code and third party code
Are Abstractions Right For You?
Slide 19
Map out the basic interface 2. Create a plugin using the interface 3. Update Vue components to use the plugin
How Do I Create One?
Slide 20
Map Out The Interface • Try not to think about the current implementation • Think generically, “what would all [whatever] need?” Simple Example: Chat Provider open() - Tells the chat provider to show the chat panel
Slide 21
Create The Plugin Using The Interface
/plugins/chat.client.js
Slide 22
Use The Abstraction
• No more vendor specific code in the component(s) • Switch chat providers without changing any of this code ChatButton.vue
Slide 23
Marketing Wants To Track Everything Problem 3
Slide 24
Track All The Things.. Pr o
du c d Ct
site
evi
er R
Us
d e w l i e P c Price RVie Pro k w o e d e y d a i r A s ngetFVi du ego B i d a i t l t c n e a i t r c o n C a t P l i e c C Lis me odu n k r e t r m d a o C C r r t a o F T P V l P d N e i i e c e a d m d w d k g a A n e e e C a d d S r c B d
roll
Slide 25
Multiple Third Parties Want To Know Not only do they want to track all the things, but want multiple providers to know about it.
Segment Chat Clicked
Full Story Optimizely
Slide 26
? t i x fi e w o d w o H
Slide 27
The Event Bus
Still using plugins..
Slide 28
How It Works
Button Clicked Hey everyone, they clicked ‘Chat’
• Integrations
subscribe to events they care about
• Your code emits
events to the bus
• Subscribers send info to their overlords
ChatClicked
Purchased
NavClicked
Segment
Segment
FullStory
FullStory
Ok Sweet!
The Event Bus
Slide 29
How Do I Make One?
Slide 30
Step 1: Create The Bus (Yep, That’s It)
Slide 31
Step 2: Setup Plugins To Listen To Bus Events
Slide 32
Step 3: Emit Events To The Bus From Components
Slide 33
Caution
This Is NOT For Component Communication!
This is not a replacement for standard emits for cross component communication. That would be horribly bad, this is just for emitting UI events to your third party providers. With great power comes great responsibility, do not take this warning lightly. Not available in all areas. Terms are subject to change without notice. All rights reserved. Only one winner per entry. No animals were harmed creating this presentation. Ok fine there was an incident with a goat, but he’s totally fine and honestly he had it coming.
Slide 34
• Over 95 video lessons • Over 10 hours of content • Exclusive Discord Channel • 25% of Sales Go To Nuxt! • Codebase will be updated to Nuxt 3 (when stable)
Slide 35
The End! Josh Deltener
Nuxt Ambassador / Runs With Scissors
deltener.com @JoshDeltener