### Run All Setup Steps Source: https://github.com/agoodway/goodanalytics/blob/main/README.md Execute both the database setup and UA inspector download in one command. ```bash mix setup ``` -------------------------------- ### Explicit Two-Script Installation Source: https://github.com/agoodway/goodanalytics/blob/main/README.md An alternative installation method using explicit script tags for the core library and the Thumbmark module. ```html ``` -------------------------------- ### Run Database Setup Source: https://github.com/agoodway/goodanalytics/blob/main/README.md Generate and run the Ecto migrations to create the necessary database schema and tables. ```bash mix good_analytics.setup mix ecto.migrate ``` -------------------------------- ### Bootstrap Migration File Source: https://github.com/agoodway/goodanalytics/blob/main/README.md The generated setup migration file that initializes the GoodAnalytics schema and partitions. ```elixir defmodule MyApp.Repo.Migrations.SetupGoodAnalytics do use Ecto.Migration def up do GoodAnalytics.Migration.up() GoodAnalytics.PartitionManager.ensure_initial_partitions() end def down, do: GoodAnalytics.Migration.down() end ``` -------------------------------- ### Configure Mix Aliases Source: https://github.com/agoodway/goodanalytics/blob/main/README.md Chain library setup with your application's migration workflow in mix.exs. ```elixir # mix.exs defp aliases do [ "ecto.setup": [ "ecto.create", "ecto.migrate", "good_analytics.setup", "ecto.migrate", "run priv/repo/seeds.exs" ] ] end ``` -------------------------------- ### GET /ga/api/visitors Source: https://github.com/agoodway/goodanalytics/blob/main/README.md List visitors for the workspace. ```APIDOC ## GET /ga/api/visitors ### Description Retrieve a paginated list of visitors. ### Method GET ### Endpoint /ga/api/visitors ### Query Parameters - **limit** (integer) - Optional - Number of items to return - **offset** (integer) - Optional - Number of items to skip ``` -------------------------------- ### GET /ga/api/links Source: https://github.com/agoodway/goodanalytics/blob/main/README.md List links for the authenticated workspace. ```APIDOC ## GET /ga/api/links ### Description Retrieve a paginated list of links for the workspace. ### Method GET ### Endpoint /ga/api/links ### Query Parameters - **limit** (integer) - Optional - Number of items to return - **offset** (integer) - Optional - Number of items to skip ``` -------------------------------- ### GET /ga/api/links/:id/stats Source: https://github.com/agoodway/goodanalytics/blob/main/README.md Retrieve aggregate statistics for a specific link. ```APIDOC ## GET /ga/api/links/:id/stats ### Description Get aggregate counters including clicks, leads, and revenue for a link. ### Method GET ### Endpoint /ga/api/links/:id/stats ``` -------------------------------- ### Phoenix Controller GET Request Tracking Source: https://github.com/agoodway/goodanalytics/blob/main/README.md Resolves a visitor from tracking signals assigned by the GoodAnalytics plug and tracks a custom event. ```elixir def show(conn, _params) do workspace_id = conn.assigns.workspace_id || GoodAnalytics.default_workspace_id() {:ok, visitor} = GoodAnalytics.resolve_visitor(conn.assigns.ga_signals, workspace_id: workspace_id ) {:ok, _event} = GoodAnalytics.track(visitor, "custom", %{ event_name: "Viewed Dashboard", url: Phoenix.Controller.current_url(conn) }) render(conn, :show) end ``` -------------------------------- ### Run the Test Suite Source: https://github.com/agoodway/goodanalytics/blob/main/README.md Commands to prepare dependencies, set up the test database, and execute the test suite. ```bash mix deps.get mix test.setup # creates the test database mix test ``` -------------------------------- ### GoodAnalytics.init(options) Source: https://github.com/agoodway/goodanalytics/blob/main/README.md Initializes the GoodAnalytics JavaScript tracking client with specific configuration options. ```APIDOC ## GoodAnalytics.init(options) ### Description Initializes the tracking client. This method sets up the tracking beacon endpoint and configures behavior for fingerprinting, anonymous ID generation, and SPA navigation tracking. ### Parameters - **endpoint** (string) - Required - Path to the tracking beacon endpoint. - **fingerprint** (boolean/string) - Optional - If true, self-loads Thumbmark from the tracking host. If a string, uses a precomputed fingerprint. - **clientAnonymousId** (boolean) - Optional - Defaults to false. If true, mints and persists a durable client-side anonymous ID. - **autoSpaNavigation** (boolean) - Optional - Defaults to true. Automatically tracks SPA navigation events. ### Request Example ```javascript GoodAnalytics.init({ endpoint: "/ga/t", fingerprint: true, autoSpaNavigation: false }); ``` ``` -------------------------------- ### Fetch Dependencies Source: https://github.com/agoodway/goodanalytics/blob/main/README.md Run this command in your terminal to fetch the newly added dependencies. ```bash mix deps.get ``` -------------------------------- ### Run Upgrade Tasks Source: https://github.com/agoodway/goodanalytics/blob/main/README.md Execute these commands after updating the library dependency to apply new migrations. ```bash mix good_analytics.gen.migration mix ecto.migrate ``` -------------------------------- ### Include JavaScript Client in Layout Source: https://github.com/agoodway/goodanalytics/blob/main/README.md Add the tracking script to your root layout and initialize it with fingerprinting enabled. ```html ``` -------------------------------- ### Download UA Inspector Databases Source: https://github.com/agoodway/goodanalytics/blob/main/README.md Download the required user-agent detection databases. ```bash mix ua_inspector.download ``` -------------------------------- ### Configure Connector Adapters Source: https://github.com/agoodway/goodanalytics/blob/main/README.md Register connector adapters at compile time and set a global runtime kill switch. ```elixir # config/config.exs config :good_analytics, connectors: [ GoodAnalytics.Connectors.Adapters.Meta, GoodAnalytics.Connectors.Adapters.Google, GoodAnalytics.Connectors.Adapters.LinkedIn, GoodAnalytics.Connectors.Adapters.TikTok ], dispatch_policy: {MyApp.ConnectorPolicy, :evaluate} # runtime.exs — global kill switch config :good_analytics, :connectors_enabled, true ``` -------------------------------- ### Implement Authentication Callback Source: https://github.com/agoodway/goodanalytics/blob/main/README.md Define the authentication module to verify tokens and return the workspace ID. ```elixir # lib/my_app/auth.ex defmodule MyApp.Auth do def authenticate_ga_api(token, _type) do case MyApp.ApiKeys.verify(token) do {:ok, api_key} -> {:ok, %{workspace_id: api_key.workspace_id}} :error -> {:error, :unauthorized} end end end ``` -------------------------------- ### Implement Custom Connectors Source: https://github.com/agoodway/goodanalytics/blob/main/README.md Create a custom connector by implementing the GoodAnalytics.Connectors.Connector behaviour. ```elixir defmodule MyApp.Connectors.Custom do @behaviour GoodAnalytics.Connectors.Connector @impl true def connector_type, do: :custom @impl true def supported_event_types, do: [:lead, :sale] @impl true def required_signals, do: [["my_signal"]] @impl true def credential_keys, do: ["api_key"] @impl true def build_payload(dispatch, credentials), do: {:ok, %{}} @impl true def deliver(payload, credentials), do: {:ok, %{status: 200}} @impl true def classify_error(%{status: 429}), do: :rate_limited def classify_error(%{status: 401}), do: :credential def classify_error(_), do: :transient end ``` -------------------------------- ### Configure Ecto Repository Source: https://github.com/agoodway/goodanalytics/blob/main/README.md Set the host application's Ecto repository in your configuration file. ```elixir # config/config.exs config :my_app, ecto_repos: [MyApp.Repo] config :good_analytics, repo: MyApp.Repo ``` -------------------------------- ### GoodAnalytics.submit_lead/2 Source: https://github.com/agoodway/goodanalytics/blob/main/README.md Records a lead conversion and triggers connector dispatch. ```APIDOC ## GoodAnalytics.submit_lead(visitor, data, opts) ### Description Records a lead conversion and triggers connector dispatch for enabled integrations. ### Parameters - **visitor** (struct) - Required - The resolved visitor object. - **data** (map) - Required - Lead properties. - **opts** (keyword list) - Optional - Includes :connector_signals for external platforms. ``` -------------------------------- ### Manage Per-Workspace Credentials Source: https://github.com/agoodway/goodanalytics/blob/main/README.md Enable specific connectors for a workspace and store encrypted credentials. ```elixir alias GoodAnalytics.Connectors.Settings # Enable Meta for a workspace Settings.enable_connector(workspace_id, :meta) # Store encrypted credentials Settings.put_credential(workspace_id, :meta, "access_token", "EAAx...") Settings.put_credential(workspace_id, :meta, "pixel_id", "123456") ``` -------------------------------- ### Configure Optional Cache Source: https://github.com/agoodway/goodanalytics/blob/main/README.md Optionally configure the cache settings for GoodAnalytics. ```elixir config :good_analytics, GoodAnalytics.Cache, gc_interval: :timer.hours(1), max_size: 10_000 ``` -------------------------------- ### Configure GoodAnalytics.TestRepo Source: https://github.com/agoodway/goodanalytics/blob/main/README.md Configuration for the test repository in config/test.exs, pointing to a local PostgreSQL database. ```elixir # config/test.exs config :good_analytics, GoodAnalytics.TestRepo, username: "postgres", password: "postgres", hostname: "localhost", database: "good_analytics_test", pool: Ecto.Adapters.SQL.Sandbox ``` -------------------------------- ### Serve JavaScript Client via Plug Source: https://github.com/agoodway/goodanalytics/blob/main/README.md Configure your Phoenix endpoint to serve the GoodAnalytics JavaScript files. ```elixir # lib/my_app_web/endpoint.ex plug Plug.Static, at: "/ga/js", from: {:good_analytics, "priv/static/js"}, gzip: false ``` -------------------------------- ### Add Path Dependency to mix.exs Source: https://github.com/agoodway/goodanalytics/blob/main/README.md Add the library as a local path dependency for development purposes. ```elixir def deps do [ {:good_analytics, path: "../goodanalytics"} ] end ``` -------------------------------- ### POST /ga/api/links Source: https://github.com/agoodway/goodanalytics/blob/main/README.md Create a new short link. ```APIDOC ## POST /ga/api/links ### Description Create a new short link for a workspace. ### Method POST ### Endpoint /ga/api/links ### Request Body - **domain** (string) - Required - The domain for the link - **key** (string) - Required - The unique key for the link - **url** (string) - Required - The destination URL ``` -------------------------------- ### GoodAnalytics.Connectors.Settings.enable_connector/2 Source: https://github.com/agoodway/goodanalytics/blob/main/README.md Enables a specific connector for a given workspace. ```APIDOC ## GoodAnalytics.Connectors.Settings.enable_connector(workspace_id, connector_type) ### Description Enables a connector adapter for a specific workspace. ### Parameters - **workspace_id** (any) - Required - The ID of the workspace. - **connector_type** (atom) - Required - The connector type (e.g., :meta). ``` -------------------------------- ### Configure GoodAnalytics in config.exs Source: https://github.com/agoodway/goodanalytics/blob/main/README.md Add the required repository and API secret to your Phoenix application configuration. ```elixir # config/config.exs config :good_analytics, repo: MyApp.Repo, api_key_secret: System.get_env("GA_API_KEY_SECRET") ``` -------------------------------- ### Configure REST API Authentication Source: https://github.com/agoodway/goodanalytics/blob/main/README.md Set the authentication callback in your configuration file to enable the GoodAnalytics REST API. ```elixir # config/config.exs config :good_analytics, :api_authenticate, {MyApp.Auth, :authenticate_ga_api} ``` -------------------------------- ### Run Quality Checks Source: https://github.com/agoodway/goodanalytics/blob/main/README.md Executes a suite of quality checks including compilation warnings, dependency checks, formatting, and static analysis tools. ```bash mix quality ``` -------------------------------- ### Manage Links with Elixir Source: https://github.com/agoodway/goodanalytics/blob/main/README.md Use the GoodAnalytics module to create, list, retrieve stats, fetch clicks, and archive links within a workspace. ```elixir # Create a short link {:ok, link} = GoodAnalytics.create_link(%{ workspace_id: "00000000-0000-0000-0000-000000000000", domain: "mybrand.link", key: "gw-launch", url: "https://example.com/pricing", # Optional link_type: "campaign", # "short", "referral", or "campaign" utm_source: "twitter", utm_medium: "social", utm_campaign: "launch-2026", utm_content: "hero-link", utm_term: "analytics", ios_url: "myapp://pricing", android_url: "myapp://pricing", expires_at: ~U[2026-12-31 23:59:59Z], tags: ["launch", "social"], external_id: "campaign_123", metadata: %{"owner" => "growth"} }) # List links for a workspace GoodAnalytics.list_links(workspace_id, limit: 50, offset: 0) # Get link stats (aggregate counters) GoodAnalytics.link_stats(link_id) # Get recent click events for a link GoodAnalytics.link_clicks(link_id, limit: 10) # Soft-delete a link (frees domain+key for reuse) GoodAnalytics.archive_link(link_id) ``` -------------------------------- ### GoodAnalytics.submit_sale/2 Source: https://github.com/agoodway/goodanalytics/blob/main/README.md Records a sale conversion and triggers connector dispatch. ```APIDOC ## GoodAnalytics.submit_sale(visitor, data, opts) ### Description Records a sale conversion and triggers connector dispatch for enabled integrations. ### Parameters - **visitor** (struct) - Required - The resolved visitor object. - **data** (map) - Required - Sale details including amount_cents and currency. - **opts** (keyword list) - Optional - Includes :connector_signals for external platforms. ``` -------------------------------- ### Check Applied Version Source: https://github.com/agoodway/goodanalytics/blob/main/README.md Query the database to verify the currently applied GoodAnalytics schema version. ```sql SELECT obj_description('good_analytics.ga_version'::regclass); -- → 'GoodAnalytics version=12' ``` -------------------------------- ### Mount API and Documentation Routers Source: https://github.com/agoodway/goodanalytics/blob/main/README.md Mount the API router and optionally the OpenAPI/Swagger documentation router in your Phoenix router. ```elixir # lib/my_app_web/router.ex forward "/ga/api", GoodAnalytics.Api.Router ``` ```elixir forward "/api/docs", GoodAnalytics.ApiSpec.Router ``` -------------------------------- ### Manual Update Migration Source: https://github.com/agoodway/goodanalytics/blob/main/README.md Create an update migration manually to call the library's migration functions. ```elixir defmodule MyApp.Repo.Migrations.UpdateGoodAnalytics do use Ecto.Migration def up, do: GoodAnalytics.Migration.up() def down, do: GoodAnalytics.Migration.down() end ``` -------------------------------- ### Register Event Hooks Source: https://github.com/agoodway/goodanalytics/blob/main/README.md Register synchronous callbacks that execute during redirects with a 50ms timeout. ```elixir # Sync hook — runs during redirect (50ms timeout) GoodAnalytics.register_hook(:link_click, fn event, visitor -> {:ok, %{set_cookies: [{"partner_id", "abc", 30}]}} end) ``` -------------------------------- ### Retrieve Visitor Data via REST API Source: https://github.com/agoodway/goodanalytics/blob/main/README.md List visitors and fetch timeline or attribution data using the /ga/api/visitors endpoint. ```bash # List visitors (excludes merged, paginated) curl /ga/api/visitors?limit=20&offset=0 -H "Authorization: Bearer $TOKEN" # Get by ID or external ID curl /ga/api/visitors/:id ... curl /ga/api/visitors/by-external-id/cust_123 ... # Timeline and attribution curl /ga/api/visitors/:id/timeline ... curl /ga/api/visitors/:id/attribution ... # => {"attribution_path": [...], "first_source": {...}, "last_source": {...}, ...} ``` -------------------------------- ### Configure Custom Schema Prefix Source: https://github.com/agoodway/goodanalytics/blob/main/README.md Set a custom schema prefix if you are not using the default 'good_analytics' schema. ```elixir config :good_analytics, schema_prefix: "my_analytics" ``` -------------------------------- ### Configure Geo Enrichment Source: https://github.com/agoodway/goodanalytics/blob/main/README.md Configure the Geo provider and MaxMind license key for location enrichment. ```elixir config :good_analytics, :geo, provider: GoodAnalytics.Geo.Locus, loader: {:maxmind, "GeoLite2-City"} config :locus, license_key: System.get_env("MAXMIND_LICENSE_KEY") ``` -------------------------------- ### Query with Custom Prefix Source: https://github.com/agoodway/goodanalytics/blob/main/README.md Use the prefix option when querying tables if a custom schema prefix is configured. ```elixir MyApp.Repo.all(Visitor, prefix: "my_analytics") ``` -------------------------------- ### Add Git Dependency to mix.exs Source: https://github.com/agoodway/goodanalytics/blob/main/README.md Add the library as a Git dependency in your project's mix.exs file. ```elixir def deps do [ {:good_analytics, github: "agoodway/goodanalytics"} ] end ``` -------------------------------- ### POST /ga/api/events/batch Source: https://github.com/agoodway/goodanalytics/blob/main/README.md Submit multiple events in a single request. ```APIDOC ## POST /ga/api/events/batch ### Description Submit up to 100 events in a single batch request. ### Method POST ### Endpoint /ga/api/events/batch ### Request Body - **events** (array) - Required - List of event objects ``` -------------------------------- ### POST /ga/api/events Source: https://github.com/agoodway/goodanalytics/blob/main/README.md Record a single event for a visitor. ```APIDOC ## POST /ga/api/events ### Description Record a single event for a visitor. Supports idempotency by providing an idempotency_key. ### Method POST ### Endpoint /ga/api/events ### Request Body - **visitor_id** (string) - Optional - UUID of the visitor - **event_type** (string) - Required - Type of event - **amount_cents** (integer) - Optional - Amount in cents - **currency** (string) - Optional - Currency code - **idempotency_key** (string) - Optional - Key to prevent duplicate submissions ### Response #### Success Response (201) - **event_id** (string) - The ID of the created event ``` -------------------------------- ### Generate Share URLs Source: https://github.com/agoodway/goodanalytics/blob/main/README.md Create social sharing URLs for a specific link with custom titles and text. ```elixir GoodAnalytics.share_urls("https://mybrand.link/gw-launch", title: "Check this out", text: "GoodAnalytics launch" ) # => %{twitter: "https://twitter.com/intent/tweet?...", facebook: "https://www.facebook.com/sharer/...", ...} ``` -------------------------------- ### GoodAnalytics.resolve_visitor/2 Source: https://github.com/agoodway/goodanalytics/blob/main/README.md Resolves tracking signals to a visitor record within a specific workspace. ```APIDOC ## GoodAnalytics.resolve_visitor(signals, opts) ### Description Resolves tracking signals to a visitor. Signals are merged based on strong and weak identifiers. ### Parameters - **signals** (map) - Required - A map of tracking signals (e.g., ga_id, anonymous_id). - **opts** (keyword list) - Required - Options including :workspace_id. ``` -------------------------------- ### Manage Links via REST API Source: https://github.com/agoodway/goodanalytics/blob/main/README.md Perform CRUD operations and retrieve analytics for links using the /ga/api/links endpoint. ```bash # Create a link curl -X POST /ga/api/links \ -H "Authorization: Bearer $TOKEN" \ -H "Content-Type: application/json" \ -d '{"domain": "mybrand.link", "key": "promo", "url": "https://example.com/sale"}' # => 201 {"id": "uuid", "domain": "mybrand.link", ...} # List links (paginated) curl /ga/api/links?limit=10&offset=0 -H "Authorization: Bearer $TOKEN" # Get / Update / Archive a link curl /ga/api/links/:id -H "Authorization: Bearer $TOKEN" curl -X PATCH /ga/api/links/:id -d '{"url": "https://new.com"}' ... curl -X DELETE /ga/api/links/:id ... # => 204 (soft delete) # Link analytics curl /ga/api/links/:id/stats ... # => {"total_clicks": 42, "unique_clicks": 38, "total_leads": 5, "total_sales": 2, "total_revenue_cents": 9800} curl /ga/api/links/:id/clicks?limit=20 ... ``` -------------------------------- ### GoodAnalytics.Connectors.Settings.put_credential/4 Source: https://github.com/agoodway/goodanalytics/blob/main/README.md Stores encrypted credentials for a specific connector and workspace. ```APIDOC ## GoodAnalytics.Connectors.Settings.put_credential(workspace_id, connector_type, key, value) ### Description Stores encrypted credentials required for connector authentication. ### Parameters - **workspace_id** (any) - Required - The ID of the workspace. - **connector_type** (atom) - Required - The connector type. - **key** (string) - Required - The credential key (e.g., "access_token"). - **value** (string) - Required - The credential value. ``` -------------------------------- ### Record Events via REST API Source: https://github.com/agoodway/goodanalytics/blob/main/README.md Submit single, idempotent, or batch events to the /ga/api/events endpoint using a Bearer token. ```bash # Record a single event curl -X POST /ga/api/events \ -H "Authorization: Bearer $TOKEN" \ -H "Content-Type: application/json" \ -d '{"visitor_id": "uuid", "event_type": "sale", "amount_cents": 4999, "currency": "USD"}' # => 201 {"event_id": "uuid"} # Idempotent submission (returns 200 if key already used) curl -X POST /ga/api/events \ -H "Authorization: Bearer $TOKEN" \ -H "Content-Type: application/json" \ -d '{"visitor_id": "uuid", "event_type": "sale", "idempotency_key": "order-123"}' # Batch events (up to 100, partial success returns 207) curl -X POST /ga/api/events/batch \ -H "Authorization: Bearer $TOKEN" \ -H "Content-Type: application/json" \ -d '{"events": [ {"visitor_id": "uuid-1", "event_type": "sale", "amount_cents": 100}, {"person_external_id": "cust_123", "event_type": "lead"} ]}' # => 201 {"results": [{"index": 0, "status": "ok", "event_id": "..."}, ...]} ``` -------------------------------- ### Mount GoodAnalytics Routes Source: https://github.com/agoodway/goodanalytics/blob/main/README.md Integrate tracking beacons, plugs, and short link routes into your Phoenix router. ```elixir # lib/my_app_web/router.ex defmodule MyAppWeb.Router do use MyAppWeb, :router # Tracking beacon endpoints (POST /ga/t/event, POST /ga/t/click) forward "/ga/t", GoodAnalytics.Core.Tracking.Router pipeline :browser do # ... your existing plugs ... # Add the tracking plug — classifies traffic source, manages identity # cookies (_ga_good, _ga_anon), and assigns tracking signals plug GoodAnalytics.Core.Tracking.Plug end # Short link QR code endpoint pipeline :short_link_qr do plug :fetch_query_params end # Short link redirect endpoint pipeline :short_link do plug :accepts, ["html"] plug :fetch_query_params end scope "/" do pipe_through :short_link_qr get "/:key/qr", GoodAnalytics.Core.Links.QRController, :show end scope "/" do pipe_through :short_link get "/:key", GoodAnalytics.Core.Links.RedirectController, :show end end ``` -------------------------------- ### Retrieve Visitor Data Source: https://github.com/agoodway/goodanalytics/blob/main/README.md Methods for fetching visitor information, timelines, and attribution data using visitor IDs or external IDs. ```elixir GoodAnalytics.get_visitor(id) GoodAnalytics.get_visitor_by_external_id(workspace_id, "cust_123") GoodAnalytics.visitor_timeline(visitor_id) GoodAnalytics.visitor_attribution(visitor_id) ``` -------------------------------- ### GoodAnalytics.get_visitor_by_external_id/2 Source: https://github.com/agoodway/goodanalytics/blob/main/README.md Retrieves a visitor profile by their workspace-specific external ID. ```APIDOC ## GoodAnalytics.get_visitor_by_external_id(workspace_id, external_id) ### Description Retrieves a visitor profile using a workspace ID and an external customer identifier. ### Parameters - **workspace_id** (any) - Required - The ID of the workspace. - **external_id** (string) - Required - The external customer identifier. ``` -------------------------------- ### Server-Side Conversion Submission Source: https://github.com/agoodway/goodanalytics/blob/main/README.md Submits lead or sale conversions with additional connector signals for external dispatch. ```elixir # Lead conversion with connector signals {:ok, event} = GoodAnalytics.submit_lead(visitor, %{ properties: %{"form" => "contact"} }, connector_signals: %{"_fbp" => "fb.1.123", "gclid" => "abc"}) # Sale conversion with connector signals {:ok, event} = GoodAnalytics.submit_sale(visitor, %{ amount_cents: 4900, currency: "USD" }, connector_signals: %{"_fbp" => "fb.1.123"}) ``` -------------------------------- ### GoodAnalytics.get_visitor/1 Source: https://github.com/agoodway/goodanalytics/blob/main/README.md Retrieves a visitor profile by their internal ID. ```APIDOC ## GoodAnalytics.get_visitor(id) ### Description Retrieves a visitor profile using their unique internal identifier. ### Parameters - **id** (any) - Required - The internal visitor ID. ``` -------------------------------- ### GoodAnalytics.share_urls/2 Source: https://github.com/agoodway/goodanalytics/blob/main/README.md Generates social media sharing URLs for a given link. ```APIDOC ## GoodAnalytics.share_urls(url, options) ### Description Generates a map of social sharing URLs (e.g., Twitter, Facebook) for a provided link. ### Parameters - **url** (string) - Required - The target URL to share. - **options** (keyword list) - Optional - Includes :title and :text for the share metadata. ``` -------------------------------- ### Event Tracking API Source: https://github.com/agoodway/goodanalytics/blob/main/README.md Functions to record pageviews, lead conversions, and sales events for a resolved visitor. ```elixir # Record a pageview GoodAnalytics.track(visitor, "pageview", %{url: "/pricing"}) # Record a lead conversion GoodAnalytics.track_lead(visitor, %{person_external_id: "cust_123"}) # Record a sale GoodAnalytics.track_sale(visitor, %{amount_cents: 4900, currency: "USD"}) ``` -------------------------------- ### GoodAnalytics.track/3 Source: https://github.com/agoodway/goodanalytics/blob/main/README.md Records a custom event for a resolved visitor. ```APIDOC ## GoodAnalytics.track(visitor, event_name, properties) ### Description Records a custom event associated with the visitor. ### Parameters - **visitor** (struct) - Required - The resolved visitor object. - **event_name** (string) - Required - The name of the event. - **properties** (map) - Required - Event metadata. ``` -------------------------------- ### Add Locus Dependency Source: https://github.com/agoodway/goodanalytics/blob/main/README.md Add the :locus dependency to your host application for Geo enrichment. ```elixir {:locus, "~> 2.3"} ``` -------------------------------- ### GoodAnalytics.forget_visitor/1 Source: https://github.com/agoodway/goodanalytics/blob/main/README.md Removes all PII and events associated with a specific visitor for GDPR compliance. ```APIDOC ## GoodAnalytics.forget_visitor(visitor_id) ### Description GDPR compliant removal of all visitor data. ### Parameters - **visitor_id** (string) - Required - The unique identifier of the visitor. ``` -------------------------------- ### Phoenix Controller POST Request Tracking Source: https://github.com/agoodway/goodanalytics/blob/main/README.md Builds signals from cookies when the tracking plug is not run, resolves the visitor, and tracks a form submission. ```elixir def create(conn, params) do conn = Plug.Conn.fetch_cookies(conn) workspace_id = conn.assigns.workspace_id || GoodAnalytics.default_workspace_id() signals = %{ ga_id: conn.cookies["_ga_good"], anonymous_id: conn.cookies["_ga_anon"], source: conn.assigns[:ga_source] } {:ok, visitor} = GoodAnalytics.resolve_visitor(signals, workspace_id: workspace_id) {:ok, _event} = GoodAnalytics.track(visitor, "custom", %{ event_name: "Submitted Form", properties: params }) redirect(conn, to: ~p"/thanks") end ``` -------------------------------- ### GoodAnalytics.forget() Source: https://github.com/agoodway/goodanalytics/blob/main/README.md Purges all client-accessible, library-owned identity state from the browser. ```APIDOC ## GoodAnalytics.forget() ### Description Clears all client-accessible identity state, including cookies, localStorage, and in-memory fields managed by the library. Note that server-owned HttpOnly cookies are not cleared by this method. ### Usage ```javascript GoodAnalytics.forget(); ``` ``` -------------------------------- ### Authenticated Visitor Identification Source: https://github.com/agoodway/goodanalytics/blob/main/README.md Identifies a visitor using user scope data before recording an event. ```elixir {:ok, visitor} = GoodAnalytics.identify(visitor, %{ person_external_id: to_string(conn.assigns.current_scope.user.id), person_email: conn.assigns.current_scope.user.email }) GoodAnalytics.track(visitor, "lead", %{url: Phoenix.Controller.current_url(conn)}) ``` -------------------------------- ### GoodAnalytics.register_hook/2 Source: https://github.com/agoodway/goodanalytics/blob/main/README.md Registers a callback function that executes when a specific event type occurs. ```APIDOC ## GoodAnalytics.register_hook(event_type, callback) ### Description Registers a sync hook that fires on specific event types, such as link clicks. The callback receives the event and visitor data. ### Parameters - **event_type** (atom) - Required - The event identifier (e.g., :link_click). - **callback** (function) - Required - A function that returns {:ok, map} with optional configuration. ``` -------------------------------- ### Identity Resolution API Source: https://github.com/agoodway/goodanalytics/blob/main/README.md Methods for resolving visitor signals, identifying users with attributes, and removing PII for GDPR compliance. ```elixir # Resolve tracking signals to a visitor {:ok, visitor} = GoodAnalytics.resolve_visitor(signals, workspace_id: ws_id) # Associate a visitor with known person attributes {:ok, visitor} = GoodAnalytics.identify(visitor, %{ person_external_id: "cust_123", person_email: "alice@example.com", person_name: "Alice" }) # GDPR: Remove all PII and events for a visitor :ok = GoodAnalytics.forget_visitor(visitor_id) ``` -------------------------------- ### GoodAnalytics.identify/2 Source: https://github.com/agoodway/goodanalytics/blob/main/README.md Associates a resolved visitor with known person attributes such as external ID, email, and name. ```APIDOC ## GoodAnalytics.identify(visitor, attributes) ### Description Links a visitor record to a known person using provided attributes. ### Parameters - **visitor** (struct) - Required - The resolved visitor object. - **attributes** (map) - Required - Map containing person_external_id, person_email, and person_name. ``` -------------------------------- ### Disable Automatic SPA Navigation Tracking Source: https://github.com/agoodway/goodanalytics/blob/main/README.md Use this configuration to disable automatic SPA tracking if your application handles pageviews manually. ```html ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.