Quantcast
Channel: Stratigent - Customized Implementation
Viewing all articles
Browse latest Browse all 10

Sharing is Caring: Teaching Domains to Play Nice

$
0
0

As a man who enjoys coding solutions, I'll run into a frustrating problem every once in a great while: sharing information between two different domains. Suppose you have an e-commerce funnel on one domain, ABC.com, while your main site lives on XYZ.com. Your boss decides that he or she wants to see user interaction after a product is added to the cart, but before a purchase is made. Perhaps users can be directed towards certain information on XYZ.com after a card add to assist a purchase. However...

If a user adds a product on ABC.com, how does XYZ.com know? Sure, some magic might be possible on the server-side, provided both servers are owned and IT teams, if more than one are involved, are friendly. As a rule of thumb, if I can make everything happen with some JavaScript client-side magic, I leap at the chance. Enter: code and cookies. Exit: JavaScript's ability to set third-party cookies. When a cart add occurs on ABC.com, the code cannot simply throw some tracking cookies on XYZ.com. At first glance, we appear hand-cuffed. Do we skulk back into our boss's office armed with all sorts of limitations and explanations as to why it cannot be done?

Of course not!

As it turns out, IFrames provide us with a nifty little work-around. Any page can load an IFrame that points to any other page, regardless of domain. JavaScript also provides the ability to create IFrames on a page and load them with any URL. With our code, we can effectively communicate any necessary information to the other domain through an IFrame with query parameters. The JavaScript on XYZ.com can identify those parameters when the page loads and take any appropriate action. Cookie creation, image request squelching, the works.

You might be wondering, "If I create an IFrame on ABC.com, won't my page on XYZ.com look a little... out of sorts?" Fortunately, IFrames have an attribute that allows them to be hidden. The end result? The browser makes requests to "load" the other page without rendering any of the content. Unless the user is especially savvy, he or she will be none the wiser that the transaction is even taking place. If a custom page is used on XYZ.com that only contains the tracking code, the bandwidth used will be extremely small. The XYZ.com domain will know that a cart add was made, and the interactions will be tracked for future analysis.

To recap, IFrames provide a vehicle to support a client/server sort of transaction that allows one domain to communicate information to another. I have personally tested on both FireFox and IE and have enjoyed the results.

That's all I have for now. Happy coding, friends!

 

 

By Adam McArdell
About the Author:

Adam McArdell is a Senior Consultant at Stratigent.


Viewing all articles
Browse latest Browse all 10

Trending Articles