Socket
Socket
Sign inDemoInstall

vue-impression-tracker

Package Overview
Dependencies
10
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    vue-impression-tracker

This library is used to track impressions using a Vue mixin. It currently support Vue v2 applications.


Version published
Weekly downloads
2
Maintainers
1
Install size
22.8 kB
Created
Weekly downloads
 

Readme

Source

vue-impression-tracker

This library is used to track impressions using a Vue mixin. It currently support Vue v2 applications.

Mixin

This library defines a Vue Mixin which accepts props, generates an impression id, and calls your provided logImpression function when a piece of content is viewed. Include the Mixin in your component with the following code:

Tracked Component

<script setup lang="ts">
defineProps({
  // Required props:
  // The function to log the impression.
  logImpression: Function,
  // ID for the piece of content we are tracking,.
  contentId: String,
  // A function to generate a UUID.
  uuid: Function,

  // Optional props:
  // The function to log an action or click.
  logAction: Function,
  // Called when an error occurs. Defaults to console.error.
  handleError: Function,
  // Specifies the source type. Defaults to DELIVERY.
  defaultSourceType: [Number, String],
  // Specify an insertion id. Defaults to undefined.
  insertionId: String,
  // Specify an impression id. Defaults to generating one with the required uuid function.
  impressionId: String,
});
</script>

<template>
  <div>Your Content</div>
</template>

<script lang="ts">
import impressionTracker from "vue-impression-tracker";
export default {
  mixins: [impressionTracker],
};
</script>

Parent Component

Also reference the Sending Engagements on Web docs.

<script setup lang="ts">
import { createEventLogger } from 'promoted-snowplow-logger';
import { v4 } from "uuid";

const handleError = process.env.NODE_ENV !== 'production' ? (err) => { throw err; } : console.error;

const eventLogger = createEventLogger({
  enabled: true,
  platformName: 'mymarket',
  handleError,
});

const logImpression = eventLogger.logImpression;
const logAction = eventLogger.logAction;

const uuid = v4;
</script>

<template>
  <YourComponent :logImpression="logImpression" :logAction="logAction" :uuid="uuid" :handleError="handleError">
</template>

Click Handler Example

<script setup lang="ts">
defineProps({
  logAction: Function,
});
</script>
<template>
  <div v-on:click="logActionFunctor">Your Content</div>
  <div v-on:click="logActionFunctor({
      impressionId: "my-custom-impression-id"
      actionType: 2,
      elementId: "some-element-id";
      targetUrl: "https://mysite.com/content/123"
    })">With a custom impression id</div>
</template>

<script lang="ts">
import impressionTracker from "vue-impression-tracker";
export default {
  mixins: [impressionTracker],
};
</script>

Local Development

Run the watcher with: yarn build:watch.

Symlink the built module if you haven't yet.

cd dist
yarn link

Run unit tests with yarn test or link the built module to a test app.

yarn link vue-impression-tracker

Deploy

We use a GitHub action that runs semantic-release to determine how to update versions. Just do a normal code review and this should work. Depending on the message prefixes (e.g. feat: , fix: , clean: , docs: ), it'll update the version appropriately.

When doing a breaking change, add BREAKING CHANGE: to the PR. The colon is important.

FAQs

Last updated on 19 Oct 2023

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc