How to use the @times-components/tracking.withTrackingContext function in @times-components/tracking

To help you get started, we’ve selected a few @times-components/tracking examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github newsuk / times-components / packages / article-topics / __tests__ / shared.base.js View on Github external
test: () => {
        const analyticsStream = jest.fn();

        const ArticleTopicsWithTracking = withTrackingContext(ArticleTopics, {
          trackingObjectName: "Article"
        });

        const testInstance = TestRenderer.create(
           {}}
            topics={topicData}
          />
        );

        const [link] = testInstance.root.findAll(node => node.type === Link);

        link.props.onPress("event");

        expect(analyticsStream.mock.calls).toMatchSnapshot();
github newsuk / times-components / packages / pagination / pagination.showcase.web.js View on Github external
component: (_, { decorateAction }) => {
        const PaginationWithTrackingContext = withTrackingContext(Pagination, {
          trackingObjectName: "Story"
        });

        return (
           `?page=${pageNum}`}
            hideResults
            onNext={preventDefaultedAction(decorateAction)("onNext")}
            onPrev={preventDefaultedAction(decorateAction)("onPrev")}
            page={2}
          />
        );
      },
      name: "Tracking",
github newsuk / times-components / packages / article-skeleton / src / tracking / article-tracking-context.web.js View on Github external
export default Component =>
  withTrackingContext(Component, {
    getAttrs: ({ data, pageSection, navigationMode, referralUrl = "" }) => {
      let editionType = "";
      if (navigationMode) {
        const { isMyArticles, isPastSixDays } = navigationMode;
        if (isMyArticles) {
          editionType = "my articles";
        } else {
          editionType = isPastSixDays ? "past 6 days" : "current edition";
        }
      }

      return {
        articleId: get(data, "id", ""),
        article_topic_tags: get(data, "topics", []).map(topic => topic.name),
        bylines: get(
          data,
github newsuk / times-components / packages / author-profile / src / author-profile-tracking-context.js View on Github external
export default Component =>
  withTrackingContext(Component, {
    getAttrs: ({ author, page, pageSize }) => ({
      articlesCount: get(author, "articles.count", 0),
      authorName: author && author.name,
      page,
      pageSize
    }),
    trackingObjectName: "AuthorProfile"
  });
github newsuk / times-components / packages / article / src / article-tracking-context.js View on Github external
export default Component =>
  withTrackingContext(Component, {
    getAttrs: ({ data, pageSection, referralUrl = "" }) => ({
      articleId: get(data, "id", ""),
      byline: get(data, "byline[0].children[0].attributes.value", ""),
      headline: get(data, "headline", ""),
      label: get(data, "label", ""),
      pageName: `${get(data, "slug", "")}-${get(data, "shortIdentifier", "")}`,
      publishedTime: get(data, "publishedTime", ""),
      referralUrl,
      section: pageSection || get(data, "section", ""),
      template: get(data, "template", "Default"),
      topics: get(data, "topics", [])
        .map(topic => topic.name)
        .join(",")
    }),
    trackingObjectName: "Article"
  });
github newsuk / times-components / packages / article-list / article-list.showcase.js View on Github external
}
  ]);

const getProps = decorateAction => ({
  adConfig,
  analyticsStream: storybookReporter,
  emptyStateMessage:
    "Unfortunately, there are no articles relating to this page",
  fetchMore: () => Promise.resolve(),
  onArticlePress: preventDefaultedAction(decorateAction)("onArticlePress"),
  onNext: preventDefaultedAction(decorateAction)("onNext"),
  onPrev: preventDefaultedAction(decorateAction)("onPrev"),
  refetch: preventDefaultedAction(decorateAction)("refetch")
});

const TrackedArticleList = withTrackingContext(ArticleList, {
  trackingObjectName: "ArticleList"
});

const articleImageRatio = "3:2";
const count = 200;
const emptyStateMessage = "Empty State";
const page = 1;
const pageSize = 10;
const slug = "deborah-haynes";

export default {
  children: [
    {
      component: (_, { decorateAction }) => (
github newsuk / times-components / packages / related-articles / src / related-articles-tracking-context.js View on Github external
export default Component =>
  withTrackingContext(Component, {
    getAttrs: ({ slice }) => {
      const { items, lead, opinion, sliceName, support1, support2 } = slice;
      if (!sliceName) return null;
      const supports = [support1, support2];

      const supportsTracking = roles =>
        supports
          .filter(support => support !== undefined)
          .map(({ article }, index) => {
            const { headline, id, shortHeadline } = article;
            return {
              headline: getHeadline(headline, shortHeadline),
              id,
              role: roles[index + 1]
            };
          });
github newsuk / times-components / packages / section / src / section-tracking-context.js View on Github external
export default Component =>
  withTrackingContext(Component, {
    getAttrs: ({ section }) => {
      const { slices } = section;
      const firstSlice = slices[0];
      const nonName = Object.keys(firstSlice).filter(n => n !== "name")[0];
      const { article: data } = firstSlice[nonName];
      const published = DateTime.fromJSDate(
        new Date(get(data, "publishedTime", ""))
      );
      const current = DateTime.local();
      const diff = current.diff(published, "days");
      const { days } = diff.values || { days: 0.0 };
      const editionType = days > 1.0 ? "past 6 days" : "current edition";
      return {
        sectionName: section && section.title,
        edition_type: editionType,
        past_edition_date:
github newsuk / times-components / packages / topic / src / topic-tracking-context.js View on Github external
export default Component =>
  withTrackingContext(Component, {
    getAttrs: ({ topic, page, pageSize }) => ({
      page,
      pageSize,
      topicName: topic && topic.name
    }),
    trackingObjectName: "Topic"
  });
github newsuk / times-components / packages / article-skeleton / src / tracking / article-tracking-context.js View on Github external
export default Component =>
  withTrackingContext(Component, {
    getAttrs: ({ data, pageSection, referralUrl = "" }) => {
      const published = DateTime.fromJSDate(
        new Date(get(data, "publishedTime", ""))
      );
      const current = DateTime.local();
      const diff = current.diff(published, "days");
      const { days } = diff.values || { days: 0.0 };
      const editionType = days > 1.0 ? "past 6 days" : "current edition";
      return {
        articleId: get(data, "id", ""),
        article_topic_tags: get(data, "topics", []).map(topic => topic.slug),
        bylines: get(
          data,
          "bylines[0].byline[0].children[0].attributes.value",
          ""
        ),

@times-components/tracking

Tracking

BSD-3-Clause
Latest version published 6 months ago

Package Health Score

80 / 100
Full package analysis