|
| 1 | +import React, { useEffect } from "react"; |
| 2 | +import ContentSecurityPolicy from "./components/ContentSecurityPolicy"; |
| 3 | +import { Link, Route, Switch, useRouteMatch } from "react-router-dom"; |
| 4 | +import { |
| 5 | + getFormBasedOffer, |
| 6 | + personalizationEvent |
| 7 | +} from "./personalizationAnalyticsClientSideHelper"; |
| 8 | + |
| 9 | +const Products = () => { |
| 10 | + personalizationEvent({ renderDecisions: true }); |
| 11 | + return ( |
| 12 | + <div> |
| 13 | + <h2>Products</h2> |
| 14 | + <div |
| 15 | + style={{ border: "1px solid red" }} |
| 16 | + id="personalization-products-container" |
| 17 | + > |
| 18 | + This is the personalization placeholder for the products view. |
| 19 | + Personalized content has not been loaded. |
| 20 | + </div> |
| 21 | + </div> |
| 22 | + ); |
| 23 | +}; |
| 24 | + |
| 25 | +const Cart = () => { |
| 26 | + personalizationEvent({ renderDecisions: true }); |
| 27 | + return ( |
| 28 | + <div> |
| 29 | + <h2>Cart</h2> |
| 30 | + <div |
| 31 | + style={{ border: "1px solid red" }} |
| 32 | + id="personalization-cart-container" |
| 33 | + > |
| 34 | + This is the personalization placeholder for the cart view. Personalized |
| 35 | + content has not been loaded. |
| 36 | + </div> |
| 37 | + </div> |
| 38 | + ); |
| 39 | +}; |
| 40 | + |
| 41 | +export default function PersonalizationAnalyticsClientSide() { |
| 42 | + useEffect(() => { |
| 43 | + personalizationEvent({ renderDecisions: true }); |
| 44 | + }, []); |
| 45 | + |
| 46 | + const match = useRouteMatch(); |
| 47 | + |
| 48 | + return ( |
| 49 | + <div> |
| 50 | + <ContentSecurityPolicy /> |
| 51 | + <h1>Personalization with A4T client side logging</h1> |
| 52 | + <p> |
| 53 | + This page tests rendering of activities using a <i>__view__</i> scope, |
| 54 | + collecting the analyticsTokens from the rendered propositions and |
| 55 | + trigger a Analytics hit using Data Insertion API. Important!!! If you |
| 56 | + navigated here from another sandbox view, you will probably need to |
| 57 | + refresh your browser because this is how to properly simulate a non-SPA |
| 58 | + workflow. |
| 59 | + </p> |
| 60 | + <div style={{ border: "1px solid red" }} id="personalization-container"> |
| 61 | + This is the personalization placeholder. Personalized content has not |
| 62 | + been loaded. |
| 63 | + </div> |
| 64 | + <div> |
| 65 | + <p>To retrieve a form based composed offer click on this button:</p> |
| 66 | + <button onClick={getFormBasedOffer}> |
| 67 | + Get a4t-test-scope location offer |
| 68 | + </button> |
| 69 | + |
| 70 | + <div |
| 71 | + style={{ border: "1px solid red", margin: "10px 0 10px 0" }} |
| 72 | + id="form-based-offer-container" |
| 73 | + > |
| 74 | + This is the personalization placeholder for a form based composed |
| 75 | + offer. Personalized content has not been loaded. |
| 76 | + </div> |
| 77 | + |
| 78 | + <button |
| 79 | + style={{ margin: "10px 0 10px 0" }} |
| 80 | + id="form-based-click-metric" |
| 81 | + > |
| 82 | + {" "} |
| 83 | + Click me! |
| 84 | + </button> |
| 85 | + </div> |
| 86 | + <p> This section is to simulate a SPA use case. </p> |
| 87 | + <ul> |
| 88 | + <li> |
| 89 | + <Link to={`${match.url}/products`}>Products</Link> |
| 90 | + </li> |
| 91 | + <li> |
| 92 | + <Link to={`${match.url}/cart`}>Cart</Link> |
| 93 | + </li> |
| 94 | + </ul> |
| 95 | + <Switch> |
| 96 | + <Route path={`${match.path}/products`}> |
| 97 | + <Products /> |
| 98 | + </Route> |
| 99 | + <Route path={`${match.path}/cart`}> |
| 100 | + <Cart /> |
| 101 | + </Route> |
| 102 | + </Switch> |
| 103 | + </div> |
| 104 | + ); |
| 105 | +} |
0 commit comments